Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / doscmd / video.h
1 /*
2  * Copyright (c) 1992, 1993, 1996
3  *      Berkeley Software Design, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Berkeley Software
16  *      Design, Inc.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      BSDI video.h,v 2.2 1996/04/08 19:33:12 bostic Exp
31  *
32  * $FreeBSD: src/usr.bin/doscmd/video.h,v 1.2.2.1 2002/04/25 11:04:51 tg Exp $
33  */
34
35 /*
36  * The VGA CRT Controller
37  */
38 extern u_int8_t VGA_CRTC[];
39
40 /* CRTC registers
41    
42    We use the VGA register functions and don't care about the MDA. We also
43    leave out the undocumented registers at 0x22, 0x24, 0x3?. */
44 #define CRTC_HorzTotal          0x00
45 #define CRTC_HorzDispEnd        0x01
46 #define CRTC_StartHorzBlank     0x02
47 #define CRTC_EndHorzBlank       0x03
48 #define CRTC_StartHorzRetrace   0x04
49 #define CRTC_EndHorzRetrace     0x05
50 #define CRTC_VertTotal          0x06
51 #define CRTC_Overflow           0x07
52 #define CRTC_ResetRowScan       0x08
53 #define CRTC_MaxScanLine        0x09
54 #define CRTC_CursStart          0x0a
55 #define CRTC_CursEnd            0x0b
56 #define CRTC_StartAddrHi        0x0c
57 #define CRTC_StartAddrLo        0x0d
58 #define CRTC_CurLocHi           0x0e
59 #define CRTC_CurLocLo           0x0f
60 #define CRTC_StartVertRetrace   0x10
61 #define CRTC_EndVertRetrace     0x11
62 #define CRTC_VertDispEnd        0x12
63 #define CRTC_Offset             0x13
64 #define CRTC_UnderlineLoc       0x14
65 #define CRTC_StartVertBlank     0x15
66 #define CRTC_EndVertBlank       0x16
67 #define CRTC_ModeCtrl           0x17
68 #define CRTC_LineCompare        0x18
69
70 #define CRTC_Size               0x19
71
72 /* Port addresses for the CRTC
73
74    The registers are read by
75         OUT index_port, reg_nr
76         IN  data_port, res
77
78    They are written by
79         OUT index_port, reg_nr
80         OUT data_port, value
81 */
82    
83 #define CRTC_IndexPortColor     0x03d4  /* CRTC Address Register (Color) */
84 #define CRTC_DataPortColor      0x03d5  /* CRTC Data Register (Color) */
85 #define CRTC_IndexPortMono      0x03b4  /* CRTC Address Register (Mono) */
86 #define CRTC_DataPortMono       0x03b5  /* CRTC Data Register (Mono) */
87
88 /*
89  * VGA Attribute Controller
90  */
91 extern u_int8_t VGA_ATC[];
92
93 /* ATC registers
94
95    The palette registers are here for completeness. We'll always use a
96    separate array 'palette[]' to access them in our code. */
97 #define ATC_Palette0            0x00
98 #define ATC_Palette1            0x01
99 #define ATC_Palette2            0x02
100 #define ATC_Palette3            0x03
101 #define ATC_Palette4            0x04
102 #define ATC_Palette5            0x05
103 #define ATC_Palette6            0x06
104 #define ATC_Palette7            0x07
105 #define ATC_Palette8            0x08
106 #define ATC_Palette9            0x09
107 #define ATC_PaletteA            0x0a
108 #define ATC_PaletteB            0x0b
109 #define ATC_PaletteC            0x0c
110 #define ATC_PaletteD            0x0d
111 #define ATC_PaletteE            0x0e
112 #define ATC_PaletteF            0x0f
113 #define ATC_ModeCtrl            0x10
114 #define ATC_OverscanColor       0x11
115 #define ATC_ColorPlaneEnable    0x12
116 #define ATC_HorzPixelPanning    0x13
117 #define ATC_ColorSelect         0x14
118
119 #define ATC_Size                0x15
120
121 /* Port addresses for the ATC
122
123    The ATC has a combined index/data port at 0x03c0. To quote from Ralf
124    Brown's ports list: ``Every write access to this register will toggle an
125    internal index/data selection flipflop, so that consecutive writes to index
126    & data is possible through this port. To get a defined start condition,
127    each read access to the input status register #1 (3BAh in mono / 3DAh in
128    color) resets the flipflop to load index.'' */
129 #define ATC_WritePort           0x03c0
130 #define ATC_ReadPort            0x03c1
131
132 /*
133  * VGA Sequencer Controller
134  */
135 extern u_int8_t VGA_TSC[];
136
137 /* TSC registers
138
139    We leave out the undocumented register at 0x07. */
140 #define TSC_Reset               0x00
141 #define TSC_ClockingMode        0x01
142 #define TSC_MapMask             0x02
143 #define TSC_CharMapSelect       0x03
144 #define TSC_MemoryMode          0x04
145
146 #define TSC_Size                0x05
147
148 /* Port addresses for the TSC */
149 #define TSC_IndexPort           0x03c4
150 #define TSC_DataPort            0x03c5
151
152 /*
153  * VGA Graphics Controller
154  */
155 extern u_int8_t VGA_GDC[];
156
157 /* GDC registers */
158 #define GDC_SetReset            0x00
159 #define GDC_EnableSetReset      0x01
160 #define GDC_ColorCompare        0x02
161 #define GDC_DataRotate          0x03
162 #define GDC_ReadMapSelect       0x04
163 #define GDC_Mode                0x05
164 #define GDC_Misc                0x06
165 #define GDC_ColorDontCare       0x07
166 #define GDC_BitMask             0x08
167
168 #define GDC_Size                0x09
169
170 /* Port addresses for the GDC */
171 #define GDC_IndexPort           0x03ce
172 #define GDC_DataPort            0x03cf
173
174 /*
175  * Miscellaneous VGA registers
176  */
177 u_int8_t VGA_InputStatus0;
178 u_int8_t VGA_InputStatus1;
179 u_int8_t VGA_MiscOutput;
180
181 u_int8_t VGA_DAC_PELData;
182 u_int8_t VGA_DAC_PELMask;
183 u_int8_t VGA_DAC_PELReadAddr;
184 u_int8_t VGA_DAC_PELWriteAddr;
185 u_int8_t VGA_DAC_State;
186
187 /* Port addresses for miscellaneous VGA registers */
188 #define VGA_InputStatus0Port            0x03c2  /* Read-only */
189 #define VGA_InputStatus1Port            0x03da  /* Read-only */
190 #define VGA_MiscOutputPortW             0x03c2  /* Write-only */
191 #define VGA_MiscOutputPortR             0x03cc  /* Read-only */
192
193 /* Port addresses for VGA DAC registers */
194 #define VGA_DAC_PELDataPort             0x03c9  /* Read/Write */
195 #define VGA_DAC_PELMaskPort             0x03c6  /* Read/Write */
196 #define VGA_DAC_PELReadAddrPort         0x03c7  /* Write-only */
197 #define VGA_DAC_PELWriteAddrPort        0x03c8  /* Read/Write */
198 #define VGA_DAC_StatePortOut            0x03c7  /* Read-only */
199
200 /*
201  * Additional variables and type definitions
202  */
203
204 /* To ease access to the palette registers, 'palette[]' will overlay the
205    Attribute Controller space. */
206 u_int8_t *palette;
207
208 /* Entry type for the DAC table. Each value is actually 6 bits wide. */
209 struct dac_colors {
210     u_int8_t red;
211     u_int8_t green;
212     u_int8_t blue;
213 };
214
215 /* We need a working copy of the default DAC table. This is filled from
216    'dac_default{64,256}[]' in 'video.c:init_vga()'. */
217 struct dac_colors *dac_rgb;
218
219 /*
220  * Video memory
221  *
222  * The video memory of a standard VGA card is 256K. For the standard modes,
223  * this is divided into four planes of 64K which are accessed according to the
224  * GDC state. Mode 0x13 will also fit within 64K. The higher resolution modes
225  * (VESA) require a bit more sophistication; we leave that for later
226  * implementation.
227  */
228
229 /* Video RAM */
230 u_int8_t *vram;
231
232 /* Pointers to the four bit planes */
233 u_int8_t *vplane0;
234 u_int8_t *vplane1;
235 u_int8_t *vplane2;
236 u_int8_t *vplane3;
237
238 /* Pointer to the video memory. The base address varies with the video mode.
239    'vmem' is used directly only in the text modes; in the graphics modes, all
240    writes go to 'vram'. */
241 u_int16_t *vmem;
242
243 /*
244  * VGA status information
245  *
246  * Int 10:1b returns a 64 byte block of status info for the VGA card. This
247  * block also contains a couple of BIOS variables, so we will use it for
248  * general housekeeping.
249  */
250 extern u_int8_t vga_status[];
251
252 /* Access to the VGA status fields. */
253 #define StaticFuncTbl           *(u_int32_t *)&vga_status[0]
254 #define VideoMode               *(u_int8_t *)&vga_status[4]
255 #define DpyCols                 *(u_int16_t *)&vga_status[5]
256 #define DpyPageSize             *(u_int16_t *)&vga_status[7]
257 #define ActivePageOfs           *(u_int16_t *)&vga_status[9]
258 #define CursCol0                *(u_int8_t *)&vga_status[11]
259 #define CursRow0                *(u_int8_t *)&vga_status[12]
260 #define CursCol1                *(u_int8_t *)&vga_status[13]
261 #define CursRow1                *(u_int8_t *)&vga_status[14]
262 #define CursCol2                *(u_int8_t *)&vga_status[15]
263 #define CursRow2                *(u_int8_t *)&vga_status[16]
264 #define CursCol3                *(u_int8_t *)&vga_status[17]
265 #define CursRow3                *(u_int8_t *)&vga_status[18]
266 #define CursCol4                *(u_int8_t *)&vga_status[19]
267 #define CursRow4                *(u_int8_t *)&vga_status[20]
268 #define CursCol5                *(u_int8_t *)&vga_status[21]
269 #define CursRow5                *(u_int8_t *)&vga_status[22]
270 #define CursCol6                *(u_int8_t *)&vga_status[23]
271 #define CursRow6                *(u_int8_t *)&vga_status[24]
272 #define CursCol7                *(u_int8_t *)&vga_status[25]
273 #define CursRow7                *(u_int8_t *)&vga_status[26]
274 #define CursStart               *(u_int8_t *)&vga_status[27]
275 #define CursEnd                 *(u_int8_t *)&vga_status[28]
276 #define ActivePage              *(u_int8_t *)&vga_status[29]
277 #define CRTCPort                *(u_int16_t *)&vga_status[30]
278 #define CGA_ModeCtrl            *(u_int8_t *)&vga_status[32]
279 #define CGA_ColorSelect         *(u_int8_t *)&vga_status[33]
280 #define DpyRows                 *(u_int8_t *)&vga_status[34]
281 #define CharHeight              *(u_int16_t *)&vga_status[35]
282 #define ActiveDCC               *(u_int8_t *)&vga_status[37]
283 #define SecondDCC               *(u_int8_t *)&vga_status[38]
284 #define NumColors               *(u_int16_t *)&vga_status[39]
285 #define NumPages                *(u_int8_t *)&vga_status[41]
286 #define VertResolution          *(u_int8_t *)&vga_status[42]
287 #define PrimaryCharset          *(u_int8_t *)&vga_status[43]
288 #define SecondaryCharset        *(u_int8_t *)&vga_status[44]
289 #define MiscStatus              *(u_int8_t *)&vga_status[45]
290 /*
291 #define Reserved1               *(u_int16_t *)&vga_status[46]
292 #define Reserved2               *(u_int8_t *)&vga_status[48]
293 */
294 #define VMemSize                *(u_int8_t *)&vga_status[49]
295 #define SavePointerStatus       *(u_int8_t *)&vga_status[50]
296
297 /* VGA Static Functionality Table
298
299    This table contains mode-independent VGA status information. It is actually
300    defined in 'vparam.h'; the declaration here is just for completeness. */
301 extern u_int8_t static_functionality_tbl[];
302
303 /* Add some names for the VGA related BIOS variables. */
304 #define BIOS_VideoMode          *(u_int8_t *)&BIOSDATA[0x49]
305 #define BIOS_DpyCols            *(u_int16_t *)&BIOSDATA[0x4a]
306 #define BIOS_DpyPageSize        *(u_int16_t *)&BIOSDATA[0x4c]
307 #define BIOS_ActivePageOfs      *(u_int16_t *)&BIOSDATA[0x4e]
308 #define BIOS_CursCol0           *(u_int8_t *)&BIOSDATA[0x50]
309 #define BIOS_CursRow0           *(u_int8_t *)&BIOSDATA[0x51]
310 #define BIOS_CursCol1           *(u_int8_t *)&BIOSDATA[0x52]
311 #define BIOS_CursRow1           *(u_int8_t *)&BIOSDATA[0x53]
312 #define BIOS_CursCol2           *(u_int8_t *)&BIOSDATA[0x54]
313 #define BIOS_CursRow2           *(u_int8_t *)&BIOSDATA[0x55]
314 #define BIOS_CursCol3           *(u_int8_t *)&BIOSDATA[0x56]
315 #define BIOS_CursRow3           *(u_int8_t *)&BIOSDATA[0x57]
316 #define BIOS_CursCol4           *(u_int8_t *)&BIOSDATA[0x58]
317 #define BIOS_CursRow4           *(u_int8_t *)&BIOSDATA[0x59]
318 #define BIOS_CursCol5           *(u_int8_t *)&BIOSDATA[0x5a]
319 #define BIOS_CursRow5           *(u_int8_t *)&BIOSDATA[0x5b]
320 #define BIOS_CursCol6           *(u_int8_t *)&BIOSDATA[0x5c]
321 #define BIOS_CursRow6           *(u_int8_t *)&BIOSDATA[0x5d]
322 #define BIOS_CursCol7           *(u_int8_t *)&BIOSDATA[0x5e]
323 #define BIOS_CursRow7           *(u_int8_t *)&BIOSDATA[0x5f]
324 #define BIOS_CursStart          *(u_int8_t *)&BIOSDATA[0x60]
325 #define BIOS_CursEnd            *(u_int8_t *)&BIOSDATA[0x61]
326 #define BIOS_ActivePage         *(u_int8_t *)&BIOSDATA[0x62]
327 #define BIOS_CRTCPort           *(u_int16_t *)&BIOSDATA[0x63]
328 #define BIOS_CGA_ModeCtrl       *(u_int8_t *)&BIOSDATA[0x65]
329 #define BIOS_CGA_ColorSelect    *(u_int8_t *)&BIOSDATA[0x66]
330 #define BIOS_DpyRows            *(u_int8_t *)&BIOSDATA[0x84]
331 #define BIOS_CharHeight         *(u_int16_t *)&BIOSDATA[0x85]
332 #define BIOS_SaveTablePointer   *(u_int32_t *)&BIOSDATA[0xa8]
333
334 /*
335  * Video modes
336  *
337  * This started as a big 'switch' statement in 'video.c:init_mode()' which
338  * soon became too ugly and unmanagable. So, we collect all mode related
339  * information in one table and define a couple of helper function to access
340  * it. This will also benefit the VESA support, whenever we get to that.
341  */
342 typedef struct {
343     int modenumber;             /* Mode number */
344     int paramindex;             /* Index into the parameter table */
345     int type;                   /* Text or Graphics */
346     int numcolors;              /* Number of colors */
347     int numpages;               /* Number of display pages */
348     int vrescode;               /* 0 = 200, 1 = 350, 2 = 400, 3 = 480 */
349     u_int32_t vmemaddr;         /* Video memory address */
350     const char *fontname;       /* Font name */
351 } vmode_t;
352
353 /* Types. 'NOMODE' is one of the 'forbidden' internal modes. */
354 #define TEXT            0
355 #define GRAPHICS        1
356 #define NOMODE          -1
357
358 extern vmode_t vmodelist[];
359
360 /* Font names */
361 #define FONTVGA         "vga"
362 #define FONT8x8         "vga8x8"
363 #define FONT8x14        "vga8x14"
364 #define FONT8x16        "vga8x16"       /* same as FONTVGA */
365
366 /* External functions in 'video.c'. */
367 void            init_mode(int);
368 int             find_vmode(int);
369 u_int8_t        vga_read(u_int32_t);
370 void            vga_write(u_int32_t, u_int8_t);
371 void            video_bios_init(void);
372 void            video_init(void);
373 int             vmem_pageflt(struct sigframe *);
374
375 /* Other external variables, mostly from tty.c. Needs to be cleaned up. */
376 extern int      vattr;
377 void            write_vram(void *);