2 * VGA hardware emulation
4 * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
38 static IDirectDraw
*lpddraw
= NULL
;
39 static IDirectDrawSurface
*lpddsurf
;
40 static IDirectDrawPalette
*lpddpal
;
41 static DDSURFACEDESC sdesc
;
43 static BOOL vga_retrace_vertical
;
44 static BOOL vga_retrace_horizontal
;
47 * Size and location of VGA controller window to framebuffer.
49 * Note: We support only single window even though some
50 * controllers support two. This should not be changed unless
51 * there are programs that depend on having two windows.
53 #define VGA_WINDOW_SIZE (64 * 1024)
54 #define VGA_WINDOW_START ((char *)0xa0000)
57 * Size and location of CGA controller window to framebuffer.
59 #define CGA_WINDOW_SIZE (32 * 1024)
60 #define CGA_WINDOW_START ((char *)0xb8000)
63 * VGA controller memory is emulated using linear framebuffer.
64 * This frambuffer also acts as an interface
65 * between VGA controller emulation and DirectDraw.
67 * vga_fb_width: Display width in pixels. Can be modified when
68 * display mode is changed.
69 * vga_fb_height: Display height in pixels. Can be modified when
70 * display mode is changed.
71 * vga_fb_depth: Number of bits used to store single pixel color information.
72 * Each pixel uses (vga_fb_depth+7)/8 bytes because
73 * 1-16 color modes are mapped to 256 color mode.
74 * Can be modified when display mode is changed.
75 * vga_fb_pitch: How many bytes to add to pointer in order to move
76 * from one row to another. This is fixed in VGA modes,
77 * but can be modified in SVGA modes.
78 * vga_fb_offset: Offset added to framebuffer start address in order
79 * to find the display origin. Programs use this to do
80 * double buffering and to scroll display. The value can
81 * be modified in VGA and SVGA modes.
82 * vga_fb_size: How many bytes are allocated to framebuffer.
83 * VGA framebuffers are always larger than display size and
84 * SVGA framebuffers may also be.
85 * vga_fb_data: Pointer to framebuffer start.
86 * vga_fb_window: Offset of 64k window 0xa0000 in bytes from framebuffer start.
87 * This value is >= 0, if mode uses linear framebuffer and
88 * -1, if mode uses color planes. This value is fixed
89 * in all modes except 0x13 (256 color VGA) where
90 * 0 means normal mode and -1 means Mode-X (unchained mode).
92 static int vga_fb_width
;
93 static int vga_fb_height
;
94 static int vga_fb_depth
;
95 static int vga_fb_pitch
;
96 static int vga_fb_offset
;
97 static int vga_fb_size
= 0;
98 static char *vga_fb_data
= 0;
99 static int vga_fb_window
= 0;
100 static int vga_fb_window_size
;
101 static char *vga_fb_window_data
;
102 static PALETTEENTRY
*vga_fb_palette
;
103 static unsigned vga_fb_palette_index
;
104 static unsigned vga_fb_palette_size
;
105 static BOOL vga_fb_bright
;
106 static BOOL vga_fb_enabled
;
109 * VGA text mode data.
111 * vga_text_attr: Current active attribute.
112 * vga_text_old: Last data sent to console.
113 * This is used to optimize console updates.
114 * vga_text_width: Width of the text display in characters.
115 * vga_text_height: Height of the text display in characters.
116 * vga_text_x: Current cursor X-position. Starts from zero.
117 * vga_text_y: Current cursor Y-position. Starts from zero.
118 * vga_text_console: TRUE if stdout is console,
119 * FALSE if it is regular file.
121 static BYTE vga_text_attr
;
122 static char *vga_text_old
= NULL
;
123 static BYTE vga_text_width
;
124 static BYTE vga_text_height
;
125 static BYTE vga_text_x
;
126 static BYTE vga_text_y
;
127 static BOOL vga_text_console
;
130 * VGA controller ports 0x3c0, 0x3c4, 0x3ce and 0x3d4 are
131 * indexed registers. These ports are used to select VGA controller
132 * subregister that can be written to or read from using ports 0x3c1,
133 * 0x3c5, 0x3cf or 0x3d5. Selected subregister indexes are
134 * stored in variables vga_index_*.
136 * Port 0x3c0 is special because it is both index and
137 * data-write register. Flip-flop vga_address_3c0 tells whether
138 * the port acts currently as an address register. Reading from port
139 * 0x3da resets the flip-flop to address mode.
141 static BYTE vga_index_3c0
;
142 static BYTE vga_index_3c4
;
143 static BYTE vga_index_3ce
;
144 static BYTE vga_index_3d4
;
145 static BOOL vga_address_3c0
= TRUE
;
148 * List of supported video modes.
150 * should be expanded to contain most or all information
151 * as required for SVGA VESA mode info block for VESA BIOS subsystem 1 (see _ModeInfoBlock)
152 * this will allow proper support for FIXME items in VGA/VESA mode configuration
154 * FIXME - verify and define support for VESA modes
155 * FIXME - add # bit planes, # video memory banks, & memory model
157 static WORD VGA_CurrentMode
;
158 static BOOL CGA_ColorComposite
= FALSE
; /* behave like composite monitor */
160 const VGA_MODE VGA_modelist
[] =
162 /* Mode, ModeType, TextCols, TextRows, CharWidth, CharHeight, Width, Height, Depth, Colors, ScreenPages, Supported*/
164 {0x0000, TEXT
, 40, 25, 9, 16, 360, 400, 0, 16, 8, TRUE
}, /* VGA/CGA text mode 0 */
165 {0x0001, TEXT
, 40, 25, 9, 16, 360, 400, 0, 16, 8, TRUE
}, /* VGA/CGA text mode 1 */
166 {0x0002, TEXT
, 80, 25, 9, 16, 360, 400, 0, 16, 8, TRUE
}, /* VGA/CGA text mode 2 */
167 {0x0003, TEXT
, 80, 25, 9, 16, 360, 400, 0, 16, 8, TRUE
}, /* VGA/CGA text mode 3 */
168 {0x0004, GRAPHIC
, 40, 25, 8, 8, 320, 200, 2, 4, 1, TRUE
}, /* VGA/CGA graphics mode 4 */
169 {0x0005, GRAPHIC
, 40, 25, 8, 8, 320, 200, 2, 4, 1, TRUE
}, /* VGA/CGA graphics mode 5 */
170 {0x0006, GRAPHIC
, 80, 25, 8, 8, 640, 200, 1, 2, 1, TRUE
}, /* VGA/CGA graphics mode 6 */
171 {0x0007, TEXT
, 80, 25, 9, 16, 720, 400, 0, 0, 8, FALSE
}, /* VGA text mode 7 - FIXME bad default address */
172 {0x000d, GRAPHIC
, 40, 25, 8, 8, 320, 200, 4, 16, 8, FALSE
}, /* VGA graphics mode 13 */
173 {0x000e, GRAPHIC
, 80, 25, 8, 8, 640, 200, 4, 16, 4, FALSE
}, /* VGA graphics mode 14 */
174 {0x000f, GRAPHIC
, 80, 25, 8, 14, 640, 350, 0, 0, 2, FALSE
}, /* VGA graphics mode 15 */
175 {0x0010, GRAPHIC
, 80, 25, 8, 14, 640, 350, 4, 16, 2, FALSE
}, /* VGA graphics mode 16 */
176 {0x0012, GRAPHIC
, 80, 30, 8, 16, 640, 480, 1, 2, 1, FALSE
}, /* VGA graphics mode 17 */
177 {0x0012, GRAPHIC
, 80, 30, 8, 16, 640, 480, 4, 16, 1, FALSE
}, /* VGA graphics mode 18 */
178 {0x0013, GRAPHIC
, 40, 25, 8, 8, 320, 200, 8, 256, 1, TRUE
}, /* VGA graphics mode 19 */
179 /* VESA 7-bit modes */
180 {0x006a, GRAPHIC
, 0, 0, 0, 0, 800, 600, 4, 16, 1, TRUE
}, /* VESA graphics mode, same as 0x102 */
181 /* VESA 15-bit modes */
182 {0x0100, GRAPHIC
, 0, 0, 0, 0, 640, 400, 8, 256, 1, TRUE
}, /* VESA graphics mode */
183 {0x0101, GRAPHIC
, 0, 0, 0, 0, 640, 480, 8, 256, 1, TRUE
}, /* VESA graphics mode */
184 {0x0102, GRAPHIC
, 0, 0, 0, 0, 800, 600, 4, 16, 1, TRUE
}, /* VESA graphics mode */
185 {0x0103, GRAPHIC
, 0, 0, 0, 0, 800, 600, 8, 256, 1, TRUE
}, /* VESA graphics mode */
186 {0x0104, GRAPHIC
, 0, 0, 0, 0, 1024, 768, 4, 16, 1, TRUE
}, /* VESA graphics mode */
187 {0x0105, GRAPHIC
, 0, 0, 0, 0, 1024, 768, 8, 256, 1, TRUE
}, /* VESA graphics mode */
188 {0x0106, GRAPHIC
, 0, 0, 0, 0, 1280, 1024, 4, 16, 1, TRUE
}, /* VESA graphics mode */
189 {0x0107, GRAPHIC
, 0, 0, 0, 0, 1280, 1024, 8, 256, 1, TRUE
}, /* VESA graphics mode */
190 {0x0108, TEXT
, 0, 0, 0, 0, 80, 60, 0, 0, 1, TRUE
}, /* VESA text mode */
191 {0x0109, TEXT
, 0, 0, 0, 0, 132, 25, 0, 0, 1, TRUE
}, /* VESA text mode */
192 {0x010a, TEXT
, 0, 0, 0, 0, 132, 43, 0, 0, 1, TRUE
}, /* VESA text mode */
193 {0x010b, TEXT
, 0, 0, 0, 0, 132, 50, 0, 0, 1, TRUE
}, /* VESA text mode */
194 {0x010c, TEXT
, 0, 0, 0, 0, 132, 60, 0, 0, 1, TRUE
}, /* VESA text mode */
196 {0x010d, GRAPHIC
, 0, 0, 0, 0, 320, 200, 15, 0, 1, TRUE
}, /* VESA graphics mode, 32K colors */
197 {0x010e, GRAPHIC
, 0, 0, 0, 0, 320, 200, 16, 0, 1, TRUE
}, /* VESA graphics mode, 64K colors */
198 {0x010f, GRAPHIC
, 0, 0, 0, 0, 320, 200, 24, 0, 1, TRUE
}, /* VESA graphics mode, 16.8 Million colors */
199 {0x0110, GRAPHIC
, 0, 0, 0, 0, 640, 480, 15, 0, 1, TRUE
}, /* VESA graphics mode, 32K colors */
200 {0x0111, GRAPHIC
, 0, 0, 0, 0, 640, 480, 16, 0, 1, TRUE
}, /* VESA graphics mode, 64K colors */
201 {0x0112, GRAPHIC
, 0, 0, 0, 0, 640, 480, 24, 0, 1, TRUE
}, /* VESA graphics mode, 16.8 Million colors */
202 {0x0113, GRAPHIC
, 0, 0, 0, 0, 800, 600, 15, 0, 1, TRUE
}, /* VESA graphics mode, 32K colors */
203 {0x0114, GRAPHIC
, 0, 0, 0, 0, 800, 600, 16, 0, 1, TRUE
}, /* VESA graphics mode, 64K colors */
204 {0x0115, GRAPHIC
, 0, 0, 0, 0, 800, 600, 24, 0, 1, TRUE
}, /* VESA graphics mode, 16.8 Million colors */
205 {0x0116, GRAPHIC
, 0, 0, 0, 0, 1024, 768, 15, 0, 1, TRUE
}, /* VESA graphics mode, 32K colors */
206 {0x0117, GRAPHIC
, 0, 0, 0, 0, 1024, 768, 16, 0, 1, TRUE
}, /* VESA graphics mode, 64K colors */
207 {0x0118, GRAPHIC
, 0, 0, 0, 0, 1024, 768, 24, 0, 1, TRUE
}, /* VESA graphics mode, 16.8 Million colors */
208 {0x0119, GRAPHIC
, 0, 0, 0, 0, 1280, 1024, 15, 0, 1, TRUE
}, /* VESA graphics mode, 32K colors */
209 {0x011a, GRAPHIC
, 0, 0, 0, 0, 1280, 1024, 16, 0, 1, TRUE
}, /* VESA graphics mode, 64K colors */
210 {0x011b, GRAPHIC
, 0, 0, 0, 0, 1280, 1024, 24, 0, 1, TRUE
}, /* VESA graphics mode, 16.8 Million colors */
211 {0xffff, TEXT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, FALSE
}
215 * This mutex is used to protect VGA state during asynchronous
216 * screen updates (see VGA_Poll). It makes sure that VGA state changes
217 * are atomic and the user interface is protected from flicker and
220 * The mutex actually serializes VGA operations and the screen update.
221 * Which means that whenever VGA_Poll occurs, application stalls if it
222 * tries to modify VGA state. This is not how real VGA adapters work,
223 * but it makes timing and correctness issues much easier to deal with.
225 static CRITICAL_SECTION vga_lock
;
226 static CRITICAL_SECTION_DEBUG critsect_debug
=
229 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
230 0, 0, { (DWORD_PTR
)(__FILE__
": vga_lock") }
232 static CRITICAL_SECTION vga_lock
= { &critsect_debug
, -1, 0, 0, 0, 0 };
234 typedef HRESULT (WINAPI
*DirectDrawCreateProc
)(LPGUID
,LPDIRECTDRAW
*,LPUNKNOWN
);
235 static DirectDrawCreateProc pDirectDrawCreate
;
237 static void CALLBACK
VGA_Poll( LPVOID arg
, DWORD low
, DWORD high
);
239 static HWND vga_hwnd
= NULL
;
244 static PALETTEENTRY cga_palette1
[] = {
245 {0x00, 0x00, 0x00}, /* 0 - Black */
246 {0x00, 0xAA, 0xAA}, /* 1 - Cyan */
247 {0xAA, 0x00, 0xAA}, /* 2 - Magenta */
248 {0xAA, 0xAA, 0xAA} /* 3 - White */
252 * CGA palette 1 in the bright variant
253 * intensities, when signalled to do so
256 static PALETTEENTRY cga_palette1_bright
[] = {
257 {0x00, 0x00, 0x00}, /* 0 - Black */
258 {0x55, 0xFF, 0xFF}, /* 1 - Light cyan */
259 {0xFF, 0x55, 0xFF}, /* 2 - Light magenta */
260 {0xFF, 0xFF, 0xFF}, /* 3 - Bright White */
266 static PALETTEENTRY cga_palette2
[] = {
267 {0x00, 0x00, 0x00}, /* 0 - Black */
268 {0x00, 0xAA, 0x00}, /* 1 - Green */
269 {0xAA, 0x00, 0x00}, /* 2 - Red */
270 {0xAA, 0x55, 0x00} /* 3 - Brown */
274 * CGA palette 2 in the bright variant
275 * intensities, when signalled to do so
278 static PALETTEENTRY cga_palette2_bright
[] = {
279 {0x00, 0x00, 0x00}, /* 0 - Black */
280 {0x55, 0xFF, 0x55}, /* 1 - Light green */
281 {0xFF, 0x55, 0x55}, /* 2 - Light red */
282 {0xFF, 0xFF, 0x55}, /* 3 - Yellow */
286 * VGA Palette Registers, in actual 16 bit color
287 * port 3C0H - 6 bit rgbRGB format
289 * 16 color accesses will use these pointers and insert
290 * entries from the 64-color palette (mode 18) into the default
291 * palette. --Robert 'Admiral' Coeyman
293 static char vga_16_palette
[17]={
294 0x00, /* 0 - Black */
296 0x02, /* 2 - Green */
299 0x05, /* 5 - Magenta */
300 0x14, /* 6 - Brown */
301 0x07, /* 7 - White (Light gray) */
302 0x38, /* 8 - Dark gray */
303 0x39, /* 9 - Light blue */
304 0x3a, /* A - Light green */
305 0x3b, /* B - Light cyan */
306 0x3c, /* C - Light red */
307 0x3d, /* D - Light magenta */
308 0x3e, /* E - Yellow */
309 0x3f, /* F - Bright White (White) */
310 0x00 /* Border Color */
314 * Mode 19 Default Color Register Setting
315 * DAC palette registers, converted from actual 18 bit color to 24.
317 static PALETTEENTRY vga_def_palette
[256]={
319 /* 16 colors in IRGB values */
320 {0x00, 0x00, 0x00}, /* 0 (0) - Black */
321 {0x00, 0x00, 0xAA}, /* 1 (1) - Blue */
322 {0x00, 0xAA, 0x00}, /* 2 (2) - Green */
323 {0x00, 0xAA, 0xAA}, /* 3 (3) - Cyan */
324 {0xAA, 0x00, 0x00}, /* 4 (4) - Red */
325 {0xAA, 0x00, 0xAA}, /* 5 (5) - Magenta */
326 {0xAA, 0x55, 0x00}, /* 6 (6) - Brown */
327 {0xAA, 0xAA, 0xAA}, /* 7 (7) - White (Light gray) */
328 {0x55, 0x55, 0x55}, /* 8 (8) - Dark gray */
329 {0x55, 0x55, 0xFF}, /* 9 (9) - Light blue */
330 {0x55, 0xFF, 0x55}, /* 10 (A) - Light green */
331 {0x55, 0xFF, 0xFF}, /* 11 (B) - Light cyan */
332 {0xFF, 0x55, 0x55}, /* 12 (C) - Light red */
333 {0xFF, 0x55, 0xFF}, /* 13 (D) - Light magenta */
334 {0xFF, 0xFF, 0x55}, /* 14 (E) - Yellow */
335 {0xFF, 0xFF, 0xFF}, /* 15 (F) - Bright White (White) */
336 /* 16 shades of gray */
337 {0x00, 0x00, 0x00}, /* 16 (10) */
338 {0x10, 0x10, 0x10}, /* 17 (11) */
339 {0x20, 0x20, 0x20}, /* 18 (12) */
340 {0x35, 0x35, 0x35}, /* 19 (13) */
341 {0x45, 0x45, 0x45}, /* 20 (14) */
342 {0x55, 0x55, 0x55}, /* 21 (15) */
343 {0x65, 0x65, 0x65}, /* 22 (16) */
344 {0x75, 0x75, 0x75}, /* 23 (17) */
345 {0x8A, 0x8A, 0x8A}, /* 24 (18) */
346 {0x9A, 0x9A, 0x9A}, /* 25 (19) */
347 {0xAA, 0xAA, 0xAA}, /* 26 (1A) */
348 {0xBA, 0xBA, 0xBA}, /* 27 (1B) */
349 {0xCA, 0xCA, 0xCA}, /* 28 (1C) */
350 {0xDF, 0xDF, 0xDF}, /* 29 (1D) */
351 {0xEF, 0xEF, 0xEF}, /* 30 (1E) */
352 {0xFF, 0xFF, 0xFF}, /* 31 (1F) */
353 /* High Intensity group - 72 colors in 1/3 saturation groups (20H-37H high) */
354 {0x00, 0x00, 0xFF}, /* 32 (20) */
355 {0x41, 0x00, 0xFF}, /* 33 (21) */
356 {0x82, 0x00, 0xFF}, /* 34 (22) */
357 {0xBE, 0x00, 0xFF}, /* 35 (23) */
358 {0xFF, 0x00, 0xFF}, /* 36 (24) */
359 {0xFF, 0x00, 0xBE}, /* 37 (25) */
360 {0xFF, 0x00, 0x82}, /* 38 (26) */
361 {0xFF, 0x00, 0x41}, /* 39 (27) */
362 {0xFF, 0x00, 0x00}, /* 40 (28) */
363 {0xFF, 0x41, 0x00}, /* 41 (29) */
364 {0xFF, 0x82, 0x00}, /* 42 (2A) */
365 {0xFF, 0xBE, 0x00}, /* 43 (2B) */
366 {0xFF, 0xFF, 0x00}, /* 44 (2C) */
367 {0xBE, 0xFF, 0x00}, /* 45 (2D) */
368 {0x82, 0xFF, 0x00}, /* 46 (2E) */
369 {0x41, 0xFF, 0x00}, /* 47 (2F) */
370 {0x00, 0xFF, 0x00}, /* 48 (30) */
371 {0x00, 0xFF, 0x41}, /* 49 (31) */
372 {0x00, 0xFF, 0x82}, /* 50 (32) */
373 {0x00, 0xFF, 0xBE}, /* 51 (33) */
374 {0x00, 0xFF, 0xFF}, /* 52 (34) */
375 {0x00, 0xBE, 0xFF}, /* 53 (35) */
376 {0x00, 0x82, 0xFF}, /* 54 (36) */
377 {0x00, 0x41, 0xFF}, /* 55 (37) */
378 /* High Intensity group - 72 colors in 2/3 saturation groups (38H-4FH moderate) */
379 {0x82, 0x82, 0xFF}, /* 56 (38) */
380 {0x9E, 0x82, 0xFF}, /* 57 (39) */
381 {0xBE, 0x82, 0xFF}, /* 58 (3A) */
382 {0xDF, 0x82, 0xFF}, /* 59 (3B) */
383 {0xFF, 0x82, 0xFF}, /* 60 (3C) */
384 {0xFF, 0x82, 0xDF}, /* 61 (3D) */
385 {0xFF, 0x82, 0xBE}, /* 62 (3E) */
386 {0xFF, 0x82, 0x9E}, /* 63 (3F) */
387 {0xFF, 0x82, 0x82}, /* 64 (40) */
388 {0xFF, 0x9E, 0x82}, /* 65 (41) */
389 {0xFF, 0xBE, 0x82}, /* 66 (42) */
390 {0xFF, 0xDF, 0x82}, /* 67 (43) */
391 {0xFF, 0xFF, 0x82}, /* 68 (44) */
392 {0xDF, 0xFF, 0x82}, /* 69 (45) */
393 {0xBE, 0xFF, 0x82}, /* 70 (46) */
394 {0x9E, 0xFF, 0x82}, /* 71 (47) */
395 {0x82, 0xFF, 0x82}, /* 72 (48) */
396 {0x82, 0xFF, 0x9E}, /* 73 (49) */
397 {0x82, 0xFF, 0xBE}, /* 74 (4A) */
398 {0x82, 0xFF, 0xDF}, /* 75 (4B) */
399 {0x82, 0xFF, 0xFF}, /* 76 (4C) */
400 {0x82, 0xDF, 0xFF}, /* 77 (4D) */
401 {0x82, 0xBE, 0xFF}, /* 78 (4E) */
402 {0x82, 0x9E, 0xFF}, /* 79 (4F) */
403 /* High Intensity group - 72 colors in 3/3 saturation groups (50H-67H low) */
404 {0xBA, 0xBA, 0xFF}, /* 80 (50) */
405 {0xCA, 0xBA, 0xFF}, /* 81 (51) */
406 {0xDF, 0xBA, 0xFF}, /* 82 (52) */
407 {0xEF, 0xBA, 0xFF}, /* 83 (53) */
408 {0xFF, 0xBA, 0xFF}, /* 84 (54) */
409 {0xFF, 0xBA, 0xEF}, /* 85 (55) */
410 {0xFF, 0xBA, 0xDF}, /* 86 (56) */
411 {0xFF, 0xBA, 0xCA}, /* 87 (57) */
412 {0xFF, 0xBA, 0xBA}, /* 88 (58) */
413 {0xFF, 0xCA, 0xBA}, /* 89 (59) */
414 {0xFF, 0xDF, 0xBA}, /* 90 (5A) */
415 {0xFF, 0xEF, 0xBA}, /* 91 (5B) */
416 {0xFF, 0xFF, 0xBA}, /* 92 (5C) */
417 {0xEF, 0xFF, 0xBA}, /* 93 (5D) */
418 {0xDF, 0xFF, 0xBA}, /* 94 (5E) */
419 {0xCA, 0xFF, 0xBA}, /* 95 (5F) */
420 {0xBA, 0xFF, 0xBA}, /* 96 (60) */
421 {0xBA, 0xFF, 0xCA}, /* 97 (61) */
422 {0xBA, 0xFF, 0xDF}, /* 98 (62) */
423 {0xBA, 0xFF, 0xEF}, /* 99 (63) */
424 {0xBA, 0xFF, 0xFF}, /* 100 (64) */
425 {0xBA, 0xEF, 0xFF}, /* 101 (65) */
426 {0xBA, 0xDF, 0xFF}, /* 102 (66) */
427 {0xBA, 0xCA, 0xFF}, /* 103 (67) */
428 /* Medium Intensity group - 72 colors in 1/3 saturation groups (68H-7FH high) */
429 {0x00, 0x00, 0x71}, /* 104 (68) */
430 {0x1C, 0x00, 0x71}, /* 105 (69) */
431 {0x39, 0x00, 0x71}, /* 106 (6A) */
432 {0x55, 0x00, 0x71}, /* 107 (6B) */
433 {0x71, 0x00, 0x71}, /* 108 (6C) */
434 {0x71, 0x00, 0x55}, /* 109 (6D) */
435 {0x71, 0x00, 0x39}, /* 110 (6E) */
436 {0x71, 0x00, 0x1C}, /* 111 (6F) */
437 {0x71, 0x00, 0x00}, /* 112 (70) */
438 {0x71, 0x1C, 0x00}, /* 113 (71) */
439 {0x71, 0x39, 0x00}, /* 114 (72) */
440 {0x71, 0x55, 0x00}, /* 115 (73) */
441 {0x71, 0x71, 0x00}, /* 116 (74) */
442 {0x55, 0x71, 0x00}, /* 117 (75) */
443 {0x39, 0x71, 0x00}, /* 118 (76) */
444 {0x1C, 0x71, 0x00}, /* 119 (77) */
445 {0x00, 0x71, 0x00}, /* 120 (78) */
446 {0x00, 0x71, 0x1C}, /* 121 (79) */
447 {0x00, 0x71, 0x39}, /* 122 (7A) */
448 {0x00, 0x71, 0x55}, /* 123 (7B) */
449 {0x00, 0x71, 0x71}, /* 124 (7C) */
450 {0x00, 0x55, 0x71}, /* 125 (7D) */
451 {0x00, 0x39, 0x71}, /* 126 (7E) */
452 {0x00, 0x1C, 0x71}, /* 127 (7F) */
453 /* Medium Intensity group - 72 colors in 2/3 saturation groups (80H-97H moderate) */
454 {0x39, 0x39, 0x71}, /* 128 (80) */
455 {0x45, 0x39, 0x71}, /* 129 (81) */
456 {0x55, 0x39, 0x71}, /* 130 (82) */
457 {0x61, 0x39, 0x71}, /* 131 (83) */
458 {0x71, 0x39, 0x71}, /* 132 (84) */
459 {0x71, 0x39, 0x61}, /* 133 (85) */
460 {0x71, 0x39, 0x55}, /* 134 (86) */
461 {0x71, 0x39, 0x45}, /* 135 (87) */
462 {0x71, 0x39, 0x39}, /* 136 (88) */
463 {0x71, 0x45, 0x39}, /* 137 (89) */
464 {0x71, 0x55, 0x39}, /* 138 (8A) */
465 {0x71, 0x61, 0x39}, /* 139 (8B) */
466 {0x71, 0x71, 0x39}, /* 140 (8C) */
467 {0x61, 0x71, 0x39}, /* 141 (8D) */
468 {0x55, 0x71, 0x39}, /* 142 (8E) */
469 {0x45, 0x71, 0x39}, /* 143 (8F) */
470 {0x39, 0x71, 0x39}, /* 144 (90) */
471 {0x39, 0x71, 0x45}, /* 145 (91) */
472 {0x39, 0x71, 0x55}, /* 146 (92) */
473 {0x39, 0x71, 0x61}, /* 147 (93) */
474 {0x39, 0x71, 0x71}, /* 148 (94) */
475 {0x39, 0x61, 0x71}, /* 149 (95) */
476 {0x39, 0x55, 0x71}, /* 150 (96) */
477 {0x39, 0x45, 0x71}, /* 151 (97) */
478 /* Medium Intensity group - 72 colors in 3/3 saturation groups (98H-AFH low) */
479 {0x51, 0x51, 0x71}, /* 152 (98) */
480 {0x59, 0x51, 0x71}, /* 153 (99) */
481 {0x61, 0x51, 0x71}, /* 154 (9A) */
482 {0x69, 0x51, 0x71}, /* 155 (9B) */
483 {0x71, 0x51, 0x71}, /* 156 (9C) */
484 {0x71, 0x51, 0x69}, /* 157 (9D) */
485 {0x71, 0x51, 0x61}, /* 158 (9E) */
486 {0x71, 0x51, 0x59}, /* 159 (9F) */
487 {0x71, 0x51, 0x51}, /* 160 (A0) */
488 {0x71, 0x59, 0x51}, /* 161 (A1) */
489 {0x71, 0x61, 0x51}, /* 162 (A2) */
490 {0x71, 0x69, 0x51}, /* 163 (A3) */
491 {0x71, 0x71, 0x51}, /* 164 (A4) */
492 {0x69, 0x71, 0x51}, /* 165 (A5) */
493 {0x61, 0x71, 0x51}, /* 166 (A6) */
494 {0x59, 0x71, 0x51}, /* 167 (A7) */
495 {0x51, 0x71, 0x51}, /* 168 (A8) */
496 {0x51, 0x71, 0x59}, /* 169 (A9) */
497 {0x51, 0x71, 0x61}, /* 170 (AA) */
498 {0x51, 0x71, 0x69}, /* 171 (AB) */
499 {0x51, 0x71, 0x71}, /* 172 (AC) */
500 {0x51, 0x69, 0x71}, /* 173 (AD) */
501 {0x51, 0x61, 0x71}, /* 174 (AE) */
502 {0x51, 0x59, 0x71}, /* 175 (AF) */
503 /* Low Intensity group - 72 colors in 1/3 saturation groups (B0H-C7H high) */
504 {0x00, 0x00, 0x41}, /* 176 (B0) */
505 {0x10, 0x00, 0x41}, /* 177 (B1) */
506 {0x20, 0x00, 0x41}, /* 178 (B2) */
507 {0x31, 0x00, 0x41}, /* 179 (B3) */
508 {0x41, 0x00, 0x41}, /* 180 (B4) */
509 {0x41, 0x00, 0x31}, /* 181 (B5) */
510 {0x41, 0x00, 0x20}, /* 182 (B6) */
511 {0x41, 0x00, 0x10}, /* 183 (B7) */
512 {0x41, 0x00, 0x00}, /* 184 (B8) */
513 {0x41, 0x10, 0x00}, /* 185 (B9) */
514 {0x41, 0x20, 0x00}, /* 186 (BA) */
515 {0x41, 0x31, 0x00}, /* 187 (BB) */
516 {0x41, 0x41, 0x00}, /* 188 (BC) */
517 {0x31, 0x41, 0x00}, /* 189 (BD) */
518 {0x20, 0x41, 0x00}, /* 190 (BE) */
519 {0x10, 0x41, 0x00}, /* 191 (BF) */
520 {0x00, 0x41, 0x00}, /* 192 (C0) */
521 {0x00, 0x41, 0x10}, /* 193 (C1) */
522 {0x00, 0x41, 0x20}, /* 194 (C2) */
523 {0x00, 0x41, 0x31}, /* 195 (C3) */
524 {0x00, 0x41, 0x41}, /* 196 (C4) */
525 {0x00, 0x31, 0x41}, /* 197 (C5) */
526 {0x00, 0x20, 0x41}, /* 198 (C6) */
527 {0x00, 0x10, 0x41}, /* 199 (C7) */
528 /* Low Intensity group - 72 colors in 2/3 saturation groups (C8H-DFH moderate) */
529 {0x20, 0x20, 0x41}, /* 200 (C8) */
530 {0x28, 0x20, 0x41}, /* 201 (C9) */
531 {0x31, 0x20, 0x41}, /* 202 (CA) */
532 {0x39, 0x20, 0x41}, /* 203 (CB) */
533 {0x41, 0x20, 0x41}, /* 204 (CC) */
534 {0x41, 0x20, 0x39}, /* 205 (CD) */
535 {0x41, 0x20, 0x31}, /* 206 (CE) */
536 {0x41, 0x20, 0x28}, /* 207 (CF) */
537 {0x41, 0x20, 0x20}, /* 208 (D0) */
538 {0x41, 0x28, 0x20}, /* 209 (D1) */
539 {0x41, 0x31, 0x20}, /* 210 (D2) */
540 {0x41, 0x39, 0x20}, /* 211 (D3) */
541 {0x41, 0x41, 0x20}, /* 212 (D4) */
542 {0x39, 0x41, 0x20}, /* 213 (D5) */
543 {0x31, 0x41, 0x20}, /* 214 (D6) */
544 {0x28, 0x41, 0x20}, /* 215 (D7) */
545 {0x20, 0x41, 0x20}, /* 216 (D8) */
546 {0x20, 0x41, 0x28}, /* 217 (D9) */
547 {0x20, 0x41, 0x31}, /* 218 (DA) */
548 {0x20, 0x41, 0x39}, /* 219 (DB) */
549 {0x20, 0x41, 0x41}, /* 220 (DC) */
550 {0x20, 0x39, 0x41}, /* 221 (DD) */
551 {0x20, 0x31, 0x41}, /* 222 (DE) */
552 {0x20, 0x28, 0x41}, /* 223 (DF) */
553 /* Low Intensity group - 72 colors in 3/3 saturation groups (E0H-F7H low) */
554 {0x2D, 0x2D, 0x41}, /* 223 (E0) */
555 {0x31, 0x2D, 0x41}, /* 224 (E1) */
556 {0x35, 0x2D, 0x41}, /* 225 (E2) */
557 {0x3D, 0x2D, 0x41}, /* 226 (E3) */
558 {0x41, 0x2D, 0x41}, /* 227 (E4) */
559 {0x41, 0x2D, 0x3D}, /* 228 (E5) */
560 {0x41, 0x2D, 0x35}, /* 229 (E6) */
561 {0x41, 0x2D, 0x31}, /* 230 (E7) */
562 {0x41, 0x2D, 0x2D}, /* 231 (E8) */
563 {0x41, 0x31, 0x2D}, /* 232 (E9) */
564 {0x41, 0x35, 0x2D}, /* 233 (EA) */
565 {0x41, 0x3D, 0x2D}, /* 234 (EB) */
566 {0x41, 0x41, 0x2D}, /* 235 (EC) */
567 {0x3D, 0x41, 0x2D}, /* 236 (ED) */
568 {0x35, 0x41, 0x2D}, /* 237 (EE) */
569 {0x31, 0x41, 0x2D}, /* 238 (EF) */
570 {0x2D, 0x41, 0x2D}, /* 239 (F0) */
571 {0x2D, 0x41, 0x31}, /* 240 (F1) */
572 {0x2D, 0x41, 0x35}, /* 241 (F2) */
573 {0x2D, 0x41, 0x3D}, /* 242 (F3) */
574 {0x2D, 0x41, 0x41}, /* 243 (F4) */
575 {0x2D, 0x3D, 0x41}, /* 244 (F5) */
576 {0x2D, 0x35, 0x41}, /* 245 (F6) */
577 {0x2D, 0x31, 0x41}, /* 246 (F7) */
578 /* Fill up remainder of palettes with black */
583 * Mode 18 Default Color Register Setting
584 * DAC palette registers, converted from actual 18 bit color to 24.
586 * This palette is the dos default, converted from 18 bit color to 24.
587 * It contains only 64 entries of colors--all others are zeros.
588 * --Robert 'Admiral' Coeyman
590 static PALETTEENTRY vga_def64_palette
[256]={
592 {0x00, 0x00, 0x00}, /* 0x00 Black */
593 {0x00, 0x00, 0xaa}, /* 0x01 Blue */
594 {0x00, 0xaa, 0x00}, /* 0x02 Green */
595 {0x00, 0xaa, 0xaa}, /* 0x03 Cyan */
596 {0xaa, 0x00, 0x00}, /* 0x04 Red */
597 {0xaa, 0x00, 0xaa}, /* 0x05 Magenta */
598 {0xaa, 0xaa, 0x00}, /* 0x06 */
599 {0xaa, 0xaa, 0xaa}, /* 0x07 White (Light Gray) */
600 {0x00, 0x00, 0x55}, /* 0x08 */
601 {0x00, 0x00, 0xff}, /* 0x09 */
602 {0x00, 0xaa, 0x55}, /* 0x0a */
603 {0x00, 0xaa, 0xff}, /* 0x0b */
604 {0xaa, 0x00, 0x55}, /* 0x0c */
605 {0xaa, 0x00, 0xff}, /* 0x0d */
606 {0xaa, 0xaa, 0x55}, /* 0x0e */
607 {0xaa, 0xaa, 0xff}, /* 0x0f */
608 {0x00, 0x55, 0x00}, /* 0x10 */
609 {0x00, 0x55, 0xaa}, /* 0x11 */
610 {0x00, 0xff, 0x00}, /* 0x12 */
611 {0x00, 0xff, 0xaa}, /* 0x13 */
612 {0xaa, 0x55, 0x00}, /* 0x14 Brown */
613 {0xaa, 0x55, 0xaa}, /* 0x15 */
614 {0xaa, 0xff, 0x00}, /* 0x16 */
615 {0xaa, 0xff, 0xaa}, /* 0x17 */
616 {0x00, 0x55, 0x55}, /* 0x18 */
617 {0x00, 0x55, 0xff}, /* 0x19 */
618 {0x00, 0xff, 0x55}, /* 0x1a */
619 {0x00, 0xff, 0xff}, /* 0x1b */
620 {0xaa, 0x55, 0x55}, /* 0x1c */
621 {0xaa, 0x55, 0xff}, /* 0x1d */
622 {0xaa, 0xff, 0x55}, /* 0x1e */
623 {0xaa, 0xff, 0xff}, /* 0x1f */
624 {0x55, 0x00, 0x00}, /* 0x20 */
625 {0x55, 0x00, 0xaa}, /* 0x21 */
626 {0x55, 0xaa, 0x00}, /* 0x22 */
627 {0x55, 0xaa, 0xaa}, /* 0x23 */
628 {0xff, 0x00, 0x00}, /* 0x24 */
629 {0xff, 0x00, 0xaa}, /* 0x25 */
630 {0xff, 0xaa, 0x00}, /* 0x26 */
631 {0xff, 0xaa, 0xaa}, /* 0x27 */
632 {0x55, 0x00, 0x55}, /* 0x28 */
633 {0x55, 0x00, 0xff}, /* 0x29 */
634 {0x55, 0xaa, 0x55}, /* 0x2a */
635 {0x55, 0xaa, 0xff}, /* 0x2b */
636 {0xff, 0x00, 0x55}, /* 0x2c */
637 {0xff, 0x00, 0xff}, /* 0x2d */
638 {0xff, 0xaa, 0x55}, /* 0x2e */
639 {0xff, 0xaa, 0xff}, /* 0x2f */
640 {0x55, 0x55, 0x00}, /* 0x30 */
641 {0x55, 0x55, 0xaa}, /* 0x31 */
642 {0x55, 0xff, 0x00}, /* 0x32 */
643 {0x55, 0xff, 0xaa}, /* 0x33 */
644 {0xff, 0x55, 0x00}, /* 0x34 */
645 {0xff, 0x55, 0xaa}, /* 0x35 */
646 {0xff, 0xff, 0x00}, /* 0x36 */
647 {0xff, 0xff, 0xaa}, /* 0x37 */
648 {0x55, 0x55, 0x55}, /* 0x38 Dark Gray */
649 {0x55, 0x55, 0xff}, /* 0x39 Light Blue */
650 {0x55, 0xff, 0x55}, /* 0x3a Light Green */
651 {0x55, 0xff, 0xff}, /* 0x3b Light Cyan */
652 {0xff, 0x55, 0x55}, /* 0x3c Light Red */
653 {0xff, 0x55, 0xff}, /* 0x3d Light Magenta */
654 {0xff, 0xff, 0x55}, /* 0x3e Yellow */
655 {0xff, 0xff, 0xff}, /* 0x3f White */
656 {0,0,0} /* The next 192 entries are all zeros */
659 static HANDLE VGA_timer
;
660 static HANDLE VGA_timer_thread
;
662 /* set the timer rate; called in the polling thread context */
663 static void CALLBACK
set_timer_rate( ULONG_PTR arg
)
667 when
.u
.LowPart
= when
.u
.HighPart
= 0;
668 SetWaitableTimer( VGA_timer
, &when
, arg
, VGA_Poll
, 0, FALSE
);
671 static DWORD CALLBACK
VGA_TimerThread( void *dummy
)
673 for (;;) SleepEx( INFINITE
, TRUE
);
677 static void VGA_DeinstallTimer(void)
679 if (VGA_timer_thread
)
682 * Make sure the update thread is not holding
683 * system resources when we kill it.
685 * Now, we only need to worry about update thread
686 * getting terminated while in EnterCriticalSection
687 * or WaitForMultipleObjectsEx.
689 * FIXME: Is this a problem?
691 EnterCriticalSection(&vga_lock
);
693 CancelWaitableTimer( VGA_timer
);
694 CloseHandle( VGA_timer
);
695 TerminateThread( VGA_timer_thread
, 0 );
696 CloseHandle( VGA_timer_thread
);
697 VGA_timer_thread
= 0;
699 LeaveCriticalSection(&vga_lock
);
702 * Synchronize display. This makes sure that
703 * changes to display become visible even if program
704 * terminates before update thread had time to run.
710 static void VGA_InstallTimer(unsigned Rate
)
712 if (!VGA_timer_thread
)
714 VGA_timer
= CreateWaitableTimerA( NULL
, FALSE
, NULL
);
715 VGA_timer_thread
= CreateThread( NULL
, 0, VGA_TimerThread
, NULL
, 0, NULL
);
717 QueueUserAPC( set_timer_rate
, VGA_timer_thread
, (ULONG_PTR
)Rate
);
720 static BOOL
VGA_IsTimerRunning(void)
722 return VGA_timer_thread
? TRUE
: FALSE
;
725 static HANDLE
VGA_AlphaConsole(void)
727 /* this assumes that no Win32 redirection has taken place, but then again,
728 * only 16-bit apps are likely to use this part of Wine... */
729 return GetStdHandle(STD_OUTPUT_HANDLE
);
732 static char*VGA_AlphaBuffer(void)
734 return (char *)0xb8000;
737 /*** GRAPHICS MODE ***/
740 unsigned Xres
, Yres
, Depth
;
745 /**********************************************************************
748 * Copy VGA window into framebuffer (if argument is TRUE) or
749 * part of framebuffer into VGA window (if argument is FALSE).
751 static void VGA_SyncWindow( BOOL target_is_fb
)
753 int size
= vga_fb_window_size
;
755 /* Window does not overlap framebuffer. */
756 if (vga_fb_window
>= vga_fb_size
)
759 /* Check if window overlaps framebuffer only partially. */
760 if (vga_fb_size
- vga_fb_window
< vga_fb_window_size
)
761 size
= vga_fb_size
- vga_fb_window
;
764 memmove( vga_fb_data
+ vga_fb_window
, vga_fb_window_data
, size
);
766 memmove( vga_fb_window_data
, vga_fb_data
+ vga_fb_window
, size
);
770 static void WINAPI
VGA_DoExit(ULONG_PTR arg
)
772 VGA_DeinstallTimer();
773 IDirectDrawSurface_SetPalette(lpddsurf
,NULL
);
774 IDirectDrawSurface_Release(lpddsurf
);
776 IDirectDrawPalette_Release(lpddpal
);
778 IDirectDraw_Release(lpddraw
);
782 static void WINAPI
VGA_DoSetMode(ULONG_PTR arg
)
785 ModeSet
*par
= (ModeSet
*)arg
;
788 if (lpddraw
) VGA_DoExit(0);
790 if (!pDirectDrawCreate
)
792 HMODULE hmod
= LoadLibraryA( "ddraw.dll" );
793 if (hmod
) pDirectDrawCreate
= (DirectDrawCreateProc
)GetProcAddress( hmod
, "DirectDrawCreate" );
794 if (!pDirectDrawCreate
) {
795 ERR("Can't lookup DirectDrawCreate from ddraw.dll.\n");
799 res
= pDirectDrawCreate(NULL
,&lpddraw
,NULL
);
801 ERR("DirectDraw is not available (res = 0x%x)\n",res
);
805 vga_hwnd
= CreateWindowExA(0,"STATIC","WINEDOS VGA",
806 WS_POPUP
|WS_VISIBLE
|SS_NOTIFY
,0,0,
807 par
->Xres
,par
->Yres
,0,0,0,NULL
);
809 ERR("Failed to create user window.\n");
810 IDirectDraw_Release(lpddraw
);
816 SetWindowPos(vga_hwnd
,0,0,0,par
->Xres
,par
->Yres
,SWP_NOMOVE
|SWP_NOZORDER
);
818 res
=IDirectDraw_SetCooperativeLevel(lpddraw
,vga_hwnd
,DDSCL_FULLSCREEN
|DDSCL_EXCLUSIVE
);
820 ERR("Could not set cooperative level to exclusive (0x%x)\n",res
);
823 res
=IDirectDraw_SetDisplayMode(lpddraw
,par
->Xres
,par
->Yres
,par
->Depth
);
825 ERR("DirectDraw does not support requested display mode (%dx%dx%d), res = 0x%x!\n",par
->Xres
,par
->Yres
,par
->Depth
,res
);
826 IDirectDraw_Release(lpddraw
);
831 res
=IDirectDraw_CreatePalette(lpddraw
,DDPCAPS_8BIT
,NULL
,&lpddpal
,NULL
);
833 ERR("Could not create palette (res = 0x%x)\n",res
);
834 IDirectDraw_Release(lpddraw
);
839 res
=IDirectDrawPalette_SetEntries(lpddpal
,0,0,vga_fb_palette_size
,vga_fb_palette
);
841 ERR("Could not set default palette entries (res = 0x%x)\n", res
);
844 memset(&sdesc
,0,sizeof(sdesc
));
845 sdesc
.dwSize
=sizeof(sdesc
);
846 sdesc
.dwFlags
= DDSD_CAPS
;
847 sdesc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
848 res
=IDirectDraw_CreateSurface(lpddraw
,&sdesc
,&lpddsurf
,NULL
);
849 if (res
!= S_OK
|| !lpddsurf
) {
850 ERR("DirectDraw surface is not available\n");
851 IDirectDraw_Release(lpddraw
);
855 IDirectDrawSurface_SetPalette(lpddsurf
,lpddpal
);
856 vga_retrace_vertical
= vga_retrace_horizontal
= FALSE
;
857 /* poll every 20ms (50fps should provide adequate responsiveness) */
858 VGA_InstallTimer(20);
864 /**********************************************************************\
867 * Returns mode information, given mode number
868 \**********************************************************************/
869 const VGA_MODE
*VGA_GetModeInfo(WORD mode
)
871 const VGA_MODE
*ModeInfo
= VGA_modelist
;
878 while (ModeInfo
->Mode
!= 0xffff)
880 if (ModeInfo
->Mode
== mode
)
887 static int VGA_SetGraphicMode(WORD mode
)
892 /* get info on VGA mode & set appropriately */
893 const VGA_MODE
*ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
894 /* check if we're assuming composite display */
895 if ((mode
== 6) && (CGA_ColorComposite
))
897 vga_fb_width
= (ModeInfo
->Width
/ 4);
898 vga_fb_height
= ModeInfo
->Height
;
899 vga_fb_depth
= (ModeInfo
->Depth
* 4);
903 vga_fb_width
= ModeInfo
->Width
;
904 vga_fb_height
= ModeInfo
->Height
;
905 vga_fb_depth
= ModeInfo
->Depth
;
908 vga_fb_pitch
= vga_fb_width
* ((vga_fb_depth
+ 7) / 8);
910 newSize
= vga_fb_width
* vga_fb_height
* ((vga_fb_depth
+ 7) / 8);
911 if(newSize
< 256 * 1024)
912 newSize
= 256 * 1024;
914 if(vga_fb_size
< newSize
) {
915 HeapFree(GetProcessHeap(), 0, vga_fb_data
);
916 vga_fb_data
= HeapAlloc(GetProcessHeap(), 0, newSize
);
917 vga_fb_size
= newSize
;
920 if(vga_fb_width
>= 640 || vga_fb_height
>= 480) {
921 par
.Xres
= vga_fb_width
;
922 par
.Yres
= vga_fb_height
;
929 if(vga_fb_depth
>= 8)
931 vga_fb_window_data
= VGA_WINDOW_START
;
932 vga_fb_window_size
= VGA_WINDOW_SIZE
;
933 vga_fb_palette
= vga_def_palette
;
934 vga_fb_palette_size
= 256;
938 vga_fb_window_data
= CGA_WINDOW_START
;
939 vga_fb_window_size
= CGA_WINDOW_SIZE
;
940 if(vga_fb_depth
== 2)
942 /* Select default 2 bit CGA palette */
943 vga_fb_palette
= cga_palette1
;
944 vga_fb_palette_size
= 4;
948 /* Top of VGA palette is same as 4 bit CGA palette */
949 vga_fb_palette
= vga_def_palette
;
950 vga_fb_palette_size
= 16;
953 vga_fb_palette_index
= 0;
957 /* Clean the HW buffer */
958 memset(vga_fb_window_data
, 0x00, vga_fb_window_size
);
960 /* Reset window start */
961 VGA_SetWindowStart(0);
963 par
.Depth
= (vga_fb_depth
< 8) ? 8 : vga_fb_depth
;
965 MZ_RunInThread(VGA_DoSetMode
, (ULONG_PTR
)&par
);
969 int VGA_SetMode(WORD mode
)
971 const VGA_MODE
*ModeInfo
;
972 /* get info on VGA mode & set appropriately */
973 VGA_CurrentMode
= mode
;
974 ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
976 /* check if mode is supported */
977 if (ModeInfo
->Supported
)
979 FIXME("Setting VGA mode %i - Supported mode - Improve reporting of missing capabilities for modes & modetypes.\n", mode
);
983 FIXME("Setting VGA mode %i - Unsupported mode - Will doubtfully work at all, but we'll try anyways.\n", mode
);
986 /* set up graphic or text display */
987 if (ModeInfo
->ModeType
== TEXT
)
989 VGA_SetAlphaMode(ModeInfo
->TextCols
, ModeInfo
->TextRows
);
993 return VGA_SetGraphicMode(mode
);
995 return 0; /* assume all good & return zero */
998 int VGA_GetMode(unsigned*Height
,unsigned*Width
,unsigned*Depth
)
1000 if (!lpddraw
) return 1;
1001 if (!lpddsurf
) return 1;
1002 if (Height
) *Height
=sdesc
.dwHeight
;
1003 if (Width
) *Width
=sdesc
.dwWidth
;
1004 if (Depth
) *Depth
=sdesc
.ddpfPixelFormat
.u1
.dwRGBBitCount
;
1008 static void VGA_Exit(void)
1010 if (lpddraw
) MZ_RunInThread(VGA_DoExit
, 0);
1013 void VGA_SetPalette(PALETTEENTRY
*pal
,int start
,int len
)
1015 if (!lpddraw
) return;
1016 IDirectDrawPalette_SetEntries(lpddpal
,0,start
,len
,pal
);
1019 /* set a single [char wide] color in 16 color mode. */
1020 void VGA_SetColor16(int reg
,int color
)
1024 if (!lpddraw
) return;
1025 pal
= &vga_def64_palette
[color
];
1026 IDirectDrawPalette_SetEntries(lpddpal
,0,reg
,1,pal
);
1027 vga_16_palette
[reg
]=(char)color
;
1030 /* Get a single [char wide] color in 16 color mode. */
1031 char VGA_GetColor16(int reg
)
1034 if (!lpddraw
) return 0;
1035 return vga_16_palette
[reg
];
1038 /* set all 17 [char wide] colors at once in 16 color mode. */
1039 void VGA_Set16Palette(char *Table
)
1044 if (!lpddraw
) return; /* return if we're in text only mode */
1045 memcpy( Table
, vga_16_palette
, 17 ); /* copy the entries into the table */
1047 for (c
=0; c
<17; c
++) { /* 17 entries */
1048 pal
= &vga_def64_palette
[(int)vga_16_palette
[c
]]; /* get color */
1049 IDirectDrawPalette_SetEntries(lpddpal
,0,c
,1,pal
); /* set entry */
1050 TRACE("Palette register %d set to %d\n",c
,(int)vga_16_palette
[c
]);
1051 } /* end of the counting loop */
1054 /* Get all 17 [ char wide ] colors at once in 16 color mode. */
1055 void VGA_Get16Palette(char *Table
)
1058 if (!lpddraw
) return; /* return if we're in text only mode */
1059 memcpy( vga_16_palette
, Table
, 17 ); /* copy the entries into the table */
1062 static LPSTR
VGA_Lock(unsigned*Pitch
,unsigned*Height
,unsigned*Width
,unsigned*Depth
)
1064 if (!lpddraw
) return NULL
;
1065 if (!lpddsurf
) return NULL
;
1066 if (IDirectDrawSurface_Lock(lpddsurf
,NULL
,&sdesc
,0,0) != S_OK
) {
1067 ERR("could not lock surface!\n");
1070 if (Pitch
) *Pitch
=sdesc
.u1
.lPitch
;
1071 if (Height
) *Height
=sdesc
.dwHeight
;
1072 if (Width
) *Width
=sdesc
.dwWidth
;
1073 if (Depth
) *Depth
=sdesc
.ddpfPixelFormat
.u1
.dwRGBBitCount
;
1074 return sdesc
.lpSurface
;
1077 static void VGA_Unlock(void)
1079 IDirectDrawSurface_Unlock(lpddsurf
,sdesc
.lpSurface
);
1083 * Set start of 64k window at 0xa0000 in bytes.
1084 * If value is -1, initialize color plane support.
1085 * If value is >= 0, window contains direct copy of framebuffer.
1087 void VGA_SetWindowStart(int start
)
1089 if(start
== vga_fb_window
)
1092 EnterCriticalSection(&vga_lock
);
1094 if(vga_fb_window
== -1)
1095 FIXME("Remove VGA memory emulation.\n");
1097 VGA_SyncWindow( TRUE
);
1099 vga_fb_window
= start
;
1101 if(vga_fb_window
== -1)
1102 FIXME("Install VGA memory emulation.\n");
1104 VGA_SyncWindow( FALSE
);
1106 LeaveCriticalSection(&vga_lock
);
1110 * Get start of 64k window at 0xa0000 in bytes.
1111 * Value is -1 in color plane modes.
1113 int VGA_GetWindowStart(void)
1115 return vga_fb_window
;
1119 /**********************************************************************
1122 * Callback for VGA_ShowMouse.
1124 static void WINAPI
VGA_DoShowMouse( ULONG_PTR show
)
1130 rv
= ShowCursor( show
);
1132 while( show
? (rv
< 0) : (rv
>= 0) );
1136 /**********************************************************************
1139 * If argument is TRUE, unconditionally show mouse cursor.
1140 * If argument is FALSE, unconditionally hide mouse cursor.
1141 * This only works in graphics mode.
1143 void VGA_ShowMouse( BOOL show
)
1146 MZ_RunInThread( VGA_DoShowMouse
, (ULONG_PTR
)show
);
1150 /**********************************************************************
1153 * Update the current palette
1155 * Note: When updating the current CGA palette, palette index 0
1156 * refers to palette2, and index 1 is palette1 (default palette)
1158 void VGA_UpdatePalette(void)
1160 /* Figure out which palette is used now */
1161 if(vga_fb_bright
== TRUE
)
1163 if(vga_fb_palette_index
== 0)
1165 vga_fb_palette
= cga_palette2_bright
;
1167 else if(vga_fb_palette_index
== 1)
1169 vga_fb_palette
= cga_palette1_bright
;
1174 if(vga_fb_palette_index
== 0)
1176 vga_fb_palette
= cga_palette2
;
1178 else if(vga_fb_palette_index
== 1)
1180 vga_fb_palette
= cga_palette1
;
1184 /* Now update the palette */
1185 VGA_SetPalette(vga_fb_palette
,0,4);
1188 /**********************************************************************
1191 * Select if using a "bright" palette or not.
1192 * This is a property of the CGA controller
1194 void VGA_SetBright(BOOL bright
)
1196 TRACE("%i\n", bright
);
1198 /* Remember the "bright" value used by the CGA controller */
1199 vga_fb_bright
= bright
;
1202 /**********************************************************************
1205 * Select if output is enabled or disabled
1206 * This is a property of the CGA controller
1208 static void VGA_SetEnabled(BOOL enabled
)
1210 TRACE("%i\n", enabled
);
1212 /* Check if going from enabled to disabled */
1213 if(vga_fb_enabled
== TRUE
&& enabled
== FALSE
)
1215 /* Clear frame buffer */
1216 memset(vga_fb_window_data
, 0x00, vga_fb_window_size
);
1219 /* Remember the "enabled" value */
1220 vga_fb_enabled
= enabled
;
1223 /**********************************************************************
1224 * VGA_SetPaletteIndex
1226 * Select the index of the palette which is currently in use
1227 * This is a property of the CGA controller
1229 void VGA_SetPaletteIndex(unsigned index
)
1231 TRACE("%i\n", index
);
1233 /* Remember the palette index, which is only used by CGA for now */
1234 vga_fb_palette_index
= index
;
1237 /**********************************************************************
1240 * Write data to the framebuffer
1241 * This is a property of the CGA controller, but might be supported
1242 * later by other framebuffer types
1244 void VGA_WritePixel(unsigned color
, unsigned page
, unsigned col
, unsigned row
)
1250 /* Calculate CGA byte offset */
1251 char *data
= vga_fb_window_data
;
1252 off
= row
& 1 ? (8 * 1024) : 0;
1253 off
+= (80 * (row
/2));
1256 /* Calculate bits offset */
1257 pos
= 6 - (col
%4 * 2);
1259 /* Clear current data */
1264 bits
= color
<< pos
;
1270 /* prepare the text mode video memory copy that is used to only
1271 * update the video memory line that did get updated. */
1272 static void VGA_PrepareVideoMemCopy(unsigned Xres
, unsigned Yres
)
1278 * Allocate space for char + attr.
1282 vga_text_old
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1283 vga_text_old
, Xres
* Yres
* 2 );
1285 vga_text_old
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1287 p
= VGA_AlphaBuffer();
1290 /* make sure the video mem copy contains the exact opposite of our
1291 * actual text mode memory area to make sure the screen
1292 * does get updated fully initially */
1293 for (i
=0; i
< Xres
*Yres
*2; i
++)
1294 *p2
++ = *p
++ ^ 0xff; /* XOR it */
1297 /**********************************************************************
1300 * Set VGA emulation to text mode.
1302 void VGA_SetAlphaMode(unsigned Xres
,unsigned Yres
)
1305 VGA_DeinstallTimer();
1307 VGA_PrepareVideoMemCopy(Xres
, Yres
);
1308 vga_text_width
= Xres
;
1309 vga_text_height
= Yres
;
1311 if (vga_text_x
>= vga_text_width
|| vga_text_y
>= vga_text_height
)
1312 VGA_SetCursorPos(0,0);
1314 if(vga_text_console
) {
1318 SetConsoleScreenBufferSize( VGA_AlphaConsole(), size
);
1320 /* poll every 30ms (33fps should provide adequate responsiveness) */
1321 VGA_InstallTimer(30);
1325 /**********************************************************************
1328 * Initialize VGA text mode handling and return default text mode.
1329 * This function does not set VGA emulation to text mode.
1331 void VGA_InitAlphaMode(unsigned*Xres
,unsigned*Yres
)
1333 CONSOLE_SCREEN_BUFFER_INFO info
;
1335 if(GetConsoleScreenBufferInfo( VGA_AlphaConsole(), &info
))
1337 vga_text_console
= TRUE
;
1338 vga_text_x
= info
.dwCursorPosition
.X
;
1339 vga_text_y
= info
.dwCursorPosition
.Y
;
1340 vga_text_attr
= info
.wAttributes
;
1341 *Xres
= info
.dwSize
.X
;
1342 *Yres
= info
.dwSize
.Y
;
1346 vga_text_console
= FALSE
;
1349 vga_text_attr
= 0x0f;
1355 /**********************************************************************
1358 * Get current text mode. Returns TRUE and sets resolution if
1359 * any VGA text mode has been initialized.
1361 BOOL
VGA_GetAlphaMode(unsigned*Xres
,unsigned*Yres
)
1363 if (vga_text_width
!= 0 && vga_text_height
!= 0) {
1364 *Xres
= vga_text_width
;
1365 *Yres
= vga_text_height
;
1371 void VGA_SetCursorShape(unsigned char start_options
, unsigned char end
)
1373 CONSOLE_CURSOR_INFO cci
;
1375 /* standard cursor settings:
1376 * 0x0607 == CGA, 0x0b0c == monochrome, 0x0d0e == EGA/VGA */
1378 /* calculate percentage from bottom - assuming VGA (bottom 0x0e) */
1379 cci
.dwSize
= ((end
& 0x1f) - (start_options
& 0x1f))/0x0e * 100;
1380 if (!cci
.dwSize
) cci
.dwSize
++; /* NULL cursor would make SCCI() fail ! */
1381 cci
.bVisible
= ((start_options
& 0x60) != 0x20); /* invisible ? */
1383 SetConsoleCursorInfo(VGA_AlphaConsole(),&cci
);
1386 void VGA_SetCursorPos(unsigned X
,unsigned Y
)
1392 void VGA_GetCursorPos(unsigned*X
,unsigned*Y
)
1394 if (X
) *X
= vga_text_x
;
1395 if (Y
) *Y
= vga_text_y
;
1398 static void VGA_PutCharAt(unsigned x
, unsigned y
, BYTE ascii
, int attr
)
1400 const VGA_MODE
*ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
1401 if ( ModeInfo
->ModeType
== TEXT
)
1403 char *dat
= VGA_AlphaBuffer() + ((vga_text_width
* y
+ x
) * 2);
1410 FIXME("Write %c at (%i,%i) - not yet supported in graphic modes.\n", (char)ascii
, x
, y
);
1414 void VGA_WriteChars(unsigned X
,unsigned Y
,unsigned ch
,int attr
,int count
)
1416 EnterCriticalSection(&vga_lock
);
1419 VGA_PutCharAt(X
+ count
, Y
, ch
, attr
);
1421 LeaveCriticalSection(&vga_lock
);
1424 void VGA_PutChar(BYTE ascii
)
1428 EnterCriticalSection(&vga_lock
);
1435 VGA_PutCharAt(vga_text_x
, vga_text_y
, ' ', 0);
1440 vga_text_x
+= ((vga_text_x
+ 8) & ~7) - vga_text_x
;
1456 VGA_PutCharAt(vga_text_x
, vga_text_y
, ascii
, vga_text_attr
);
1460 if (vga_text_x
>= vga_text_width
)
1466 if (vga_text_y
>= vga_text_height
)
1468 vga_text_y
= vga_text_height
- 1;
1469 VGA_ScrollUpText( 0, 0,
1470 vga_text_height
- 1, vga_text_width
- 1,
1475 * If we don't have a console, write directly to standard output.
1477 if(!vga_text_console
)
1478 WriteFile(VGA_AlphaConsole(), &ascii
, 1, &w
, NULL
);
1480 LeaveCriticalSection(&vga_lock
);
1483 void VGA_ClearText(unsigned row1
, unsigned col1
,
1484 unsigned row2
, unsigned col2
,
1489 EnterCriticalSection(&vga_lock
);
1491 for(y
=row1
; y
<=row2
; y
++)
1492 for(x
=col1
; x
<=col2
; x
++)
1493 VGA_PutCharAt(x
, y
, 0x20, attr
);
1495 LeaveCriticalSection(&vga_lock
);
1498 void VGA_ScrollUpText(unsigned row1
, unsigned col1
,
1499 unsigned row2
, unsigned col2
,
1500 unsigned lines
, BYTE attr
)
1502 char *buffer
= VGA_AlphaBuffer();
1505 EnterCriticalSection(&vga_lock
);
1510 for (y
= row1
; y
<= row2
- lines
; y
++)
1511 memmove( buffer
+ col1
+ y
* vga_text_width
* 2,
1512 buffer
+ col1
+ (y
+ lines
) * vga_text_width
* 2,
1513 (col2
- col1
+ 1) * 2 );
1516 * Fill exposed lines.
1518 for (y
= max(row1
, row2
- lines
+ 1); y
<= row2
; y
++)
1519 VGA_WriteChars( col1
, y
, ' ', attr
, col2
- col1
+ 1 );
1521 LeaveCriticalSection(&vga_lock
);
1524 void VGA_ScrollDownText(unsigned row1
, unsigned col1
,
1525 unsigned row2
, unsigned col2
,
1526 unsigned lines
, BYTE attr
)
1528 char *buffer
= VGA_AlphaBuffer();
1531 EnterCriticalSection(&vga_lock
);
1536 for (y
= row2
; y
>= row1
+ lines
; y
--)
1537 memmove( buffer
+ col1
+ y
* vga_text_width
* 2,
1538 buffer
+ col1
+ (y
- lines
) * vga_text_width
* 2,
1539 (col2
- col1
+ 1) * 2 );
1542 * Fill exposed lines.
1544 for (y
= row1
; y
<= min(row1
+ lines
- 1, row2
); y
++)
1545 VGA_WriteChars( col1
, y
, ' ', attr
, col2
- col1
+ 1 );
1547 LeaveCriticalSection(&vga_lock
);
1550 void VGA_GetCharacterAtCursor(BYTE
*ascii
, BYTE
*attr
)
1554 dat
= VGA_AlphaBuffer() + ((vga_text_width
* vga_text_y
+ vga_text_x
) * 2);
1563 /* FIXME: optimize by doing this only if the data has actually changed
1564 * (in a way similar to DIBSection, perhaps) */
1565 static void VGA_Poll_Graphics(void)
1567 unsigned int Pitch
, Height
, Width
, X
, Y
;
1569 char *dat
= vga_fb_data
+ vga_fb_offset
;
1570 int bpp
= (vga_fb_depth
+ 7) / 8;
1572 surf
= VGA_Lock(&Pitch
,&Height
,&Width
,NULL
);
1576 * Synchronize framebuffer contents.
1578 if (vga_fb_window
!= -1)
1579 VGA_SyncWindow( TRUE
);
1582 * CGA framebuffer (160x200) - CGA_ColorComposite, special subtype of mode 6
1583 * This buffer is encoded as following:
1584 * - 4 bit pr. pixel, 2 pixels per byte
1585 * - 80 bytes per row
1586 * - Every second line has an offset of 8096
1588 if(vga_fb_depth
== 4 && vga_fb_width
== 160 && vga_fb_height
== 200){
1592 for(Y
=0; Y
<vga_fb_height
; Y
++, surf
+=(Pitch
*2)){
1593 for(X
=0; X
<vga_fb_width
; X
++){
1594 off
= Y
& 1 ? (8 * 1024) : 0;
1595 off
+= (80 * (Y
/2));
1597 value
= (dat
[off
] >> bits
) & 0xF;
1598 surf
[(X
*4)+0] = value
;
1599 surf
[(X
*4)+1] = value
;
1600 surf
[(X
*4)+2] = value
;
1601 surf
[(X
*4)+3] = value
;
1602 surf
[(X
*4)+Pitch
+0] = value
;
1603 surf
[(X
*4)+Pitch
+1] = value
;
1604 surf
[(X
*4)+Pitch
+2] = value
;
1605 surf
[(X
*4)+Pitch
+3] = value
;
1613 * CGA framebuffer (320x200)
1614 * This buffer is encoded as following:
1615 * - 2 bits per color, 4 pixels per byte
1616 * - 80 bytes per row
1617 * - Every second line has an offset of 8096
1619 else if(vga_fb_depth
== 2 && vga_fb_width
== 320 && vga_fb_height
== 200){
1624 for(Y
=0; Y
<vga_fb_height
; Y
++, surf
+=(Pitch
*2)){
1625 for(X
=0; X
<vga_fb_width
; X
++){
1626 off
= Y
& 1 ? (8 * 1024) : 0;
1627 off
+= (80 * (Y
/2));
1629 value
= (dat
[off
] >> bits
) & 0x3;
1630 surf
[(X
*2)] = value
;
1631 surf
[(X
*2)+1] = value
;
1632 surf
[(X
*2)+Pitch
] = value
;
1633 surf
[(X
*2)+Pitch
+1] = value
;
1641 * Double VGA framebuffer (320x200 -> 640x400), if needed.
1643 else if(Height
>= 2 * vga_fb_height
&& Width
>= 2 * vga_fb_width
&& bpp
== 1)
1644 for (Y
=0; Y
<vga_fb_height
; Y
++,surf
+=Pitch
*2,dat
+=vga_fb_pitch
)
1645 for (X
=0; X
<vga_fb_width
; X
++) {
1646 BYTE value
= dat
[X
];
1648 surf
[X
*2+1] = value
;
1649 surf
[X
*2+Pitch
] = value
;
1650 surf
[X
*2+Pitch
+1] = value
;
1653 * Linear Buffer, including mode 19
1656 for (Y
=0; Y
<vga_fb_height
; Y
++,surf
+=Pitch
,dat
+=vga_fb_pitch
)
1657 memcpy(surf
, dat
, vga_fb_width
* bpp
);
1662 static void VGA_Poll_Text(void)
1664 char *dat
, *old
, *p_line
;
1666 CHAR_INFO ch
[256]; /* that should suffice for the largest text width */
1669 HANDLE con
= VGA_AlphaConsole();
1670 BOOL linechanged
= FALSE
; /* video memory area differs from stored copy? */
1672 /* Synchronize cursor position. */
1675 SetConsoleCursorPosition(con
,off
);
1677 dat
= VGA_AlphaBuffer();
1678 old
= vga_text_old
; /* pointer to stored video mem copy */
1679 siz
.X
= vga_text_width
; siz
.Y
= 1;
1680 off
.X
= 0; off
.Y
= 0;
1682 /* copy from virtual VGA frame buffer to console */
1683 for (Y
=0; Y
<vga_text_height
; Y
++) {
1684 linechanged
= memcmp(dat
, old
, vga_text_width
*2);
1687 /*TRACE("line %d changed\n", Y);*/
1689 for (X
=0; X
<vga_text_width
; X
++) {
1690 ch
[X
].Char
.AsciiChar
= *p_line
++;
1691 /* WriteConsoleOutputA doesn't like "dead" chars */
1692 if (ch
[X
].Char
.AsciiChar
== '\0')
1693 ch
[X
].Char
.AsciiChar
= ' ';
1694 ch
[X
].Attributes
= *p_line
++;
1696 dest
.Top
=Y
; dest
.Bottom
=Y
;
1697 dest
.Left
=0; dest
.Right
=vga_text_width
+1;
1698 WriteConsoleOutputA(con
, ch
, siz
, off
, &dest
);
1699 memcpy(old
, dat
, vga_text_width
*2);
1701 /* advance to next text line */
1702 dat
+= vga_text_width
*2;
1703 old
+= vga_text_width
*2;
1707 static void CALLBACK
VGA_Poll( LPVOID arg
, DWORD low
, DWORD high
)
1709 EnterCriticalSection(&vga_lock
);
1712 VGA_Poll_Graphics();
1717 * Fake start of retrace.
1719 vga_retrace_vertical
= TRUE
;
1721 LeaveCriticalSection(&vga_lock
);
1724 static BYTE palreg
,palcnt
;
1725 static PALETTEENTRY paldat
;
1727 void VGA_ioport_out( WORD port
, BYTE val
)
1730 /* General Register - Feature Control */
1732 FIXME("Unsupported VGA register: general register - feature control 0x%04x (value 0x%02x)\n", port
, val
);
1734 /* Attribute Controller - Address/Other */
1736 if (vga_address_3c0
)
1737 vga_index_3c0
= val
;
1739 FIXME("Unsupported index, VGA attribute controller register 0x3c0: 0x%02x (value 0x%02x)\n",
1740 vga_index_3c0
, val
);
1741 vga_address_3c0
= !vga_address_3c0
;
1743 /* General Register - Misc output */
1745 FIXME("Unsupported VGA register: general register - misc output 0x%04x (value 0x%02x)\n", port
, val
);
1747 /* General Register - Video subsystem enable */
1749 FIXME("Unsupported VGA register: general register - video subsystem enable 0x%04x (value 0x%02x)\n", port
, val
);
1751 /* Sequencer Register - Address */
1753 vga_index_3c4
= val
;
1755 /* Sequencer Register - Other */
1757 switch(vga_index_3c4
) {
1758 case 0x04: /* Sequencer: Memory Mode Register */
1759 if(vga_fb_depth
== 8)
1760 VGA_SetWindowStart((val
& 8) ? 0 : -1);
1762 FIXME("Memory Mode Register not supported in this mode.\n");
1765 FIXME("Unsupported index, VGA sequencer register 0x3c4: 0x%02x (value 0x%02x)\n",
1766 vga_index_3c4
, val
);
1770 palreg
=val
; palcnt
=0; break;
1772 ((BYTE
*)&paldat
)[palcnt
++]=val
<< 2;
1774 VGA_SetPalette(&paldat
,palreg
++,1);
1778 /* Graphics Controller Register - Address */
1780 vga_index_3ce
= val
;
1782 /* Graphics Controller Register - Other */
1784 FIXME("Unsupported index, VGA graphics controller register - other 0x3ce: 0x%02x (value 0x%02x)\n",
1785 vga_index_3ce
, val
);
1787 /* CRT Controller Register - Index (MDA) */
1789 /* CRT Controller Register - Index (CGA) */
1791 vga_index_3d4
= val
;
1793 /* CRT Controller Register - Other (MDA) */
1795 /* CRT Controller Register - Other (CGA) */
1797 FIXME("Unsupported index, VGA crt controller register 0x3b4/0x3d4: 0x%02x (value 0x%02x)\n",
1798 vga_index_3d4
, val
);
1800 /* Mode control register - 6845 Motorola (MDA) */
1802 /* Mode control register - 6845 Motorola (CGA) */
1805 * xxxxxxx1 = 80x25 text
1806 * xxxxxxx0 = 40x25 text (default)
1807 * xxxxxx1x = graphics (320x200)
1811 * xxxx1xxx = enable video signal
1812 * xxx1xxxx = 640x200 B/W graphics
1816 /* check bits 6 and 7 */
1819 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x - bits 7 and 6 not supported.\n", val
);
1821 /* check bits 5 - blink on */
1824 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x (bit 5) - blink is not supported.\n", val
);
1826 /* Enable Video Signal (bit 3) - Set the enabled bit */
1827 VGA_SetEnabled((val
& 0x08) && 1);
1829 /* xxx1x010 - Detect 160x200, 16 color mode (CGA composite) */
1830 if( (val
& 0x17) == 0x12 )
1832 /* Switch to 160x200x4 composite mode - special case of mode 6 */
1833 CGA_ColorComposite
= TRUE
;
1838 /* turn off composite colors otherwise, including 320x200 (80x200 16 color) */
1839 CGA_ColorComposite
= FALSE
;
1842 /* xxx0x100 - Detect VGA mode 0 */
1843 if( (val
& 0x17) == 0x04 )
1847 /* xxx0x000 - Detect VGA mode 1 */
1848 else if( (val
& 0x17) == 0x00 )
1852 /* xxx0x101 - Detect VGA mode 2 */
1853 else if( (val
& 0x17) == 0x05 )
1857 /* xxx0x001 - Detect VGA mode 3 */
1858 else if( (val
& 0x17) == 0x01 )
1862 /* xxx0x010 - Detect VGA mode 4 */
1863 else if( (val
& 0x17) == 0x02 )
1867 /* xxx0x110 - Detect VGA mode 5 */
1868 else if( (val
& 0x17) == 0x06 )
1872 /* xxx1x110 - Detect VGA mode 6 */
1873 else if( (val
& 0x17) == 0x16 )
1877 /* unsupported mode */
1880 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x - unrecognized MDA/CGA mode\n", val
); /* Set the enabled bit */
1885 /* Colour control register (CGA) */
1888 VGA_SetBright((val
& 0x10) && 1);
1890 /* Set palette index */
1891 VGA_SetPaletteIndex((val
& 0x20) && 1);
1893 /* Now update the palette */
1894 VGA_UpdatePalette();
1897 FIXME("Unsupported VGA register: 0x%04x (value 0x%02x)\n", port
, val
);
1901 BYTE
VGA_ioport_in( WORD port
)
1906 /* Attribute Controller - Other */
1908 FIXME("Unsupported index, VGA attribute controller register 0x3c0: 0x%02x\n",
1911 /* General Register - Input status 0 */
1914 FIXME("Unsupported VGA register: general register - input status 0 0x%04x\n", port
);
1916 /* General Register - Video subsystem enable */
1919 FIXME("Unsupported VGA register: general register - video subsystem enable 0x%04x\n", port
);
1921 /* Sequencer Register - Other */
1923 switch(vga_index_3c4
) {
1924 case 0x04: /* Sequencer: Memory Mode Register */
1925 return (VGA_GetWindowStart() == -1) ? 0xf7 : 0xff;
1927 FIXME("Unsupported index, register 0x3c4: 0x%02x\n",
1931 /* General Register - DAC State */
1934 FIXME("Unsupported VGA register: general register - DAC State 0x%04x\n", port
);
1936 /* General Register - Feature control */
1939 FIXME("Unsupported VGA register: general register - Feature control 0x%04x\n", port
);
1941 /* General Register - Misc output */
1944 FIXME("Unsupported VGA register: general register - Feature control 0x%04x\n", port
);
1946 /* Graphics Controller Register - Other */
1948 FIXME("Unsupported index, register 0x3ce: 0x%02x\n",
1951 /* CRT Controller Register - Other (MDA) */
1953 /* CRT Controller Register - Other (CGA) */
1955 FIXME("Unsupported index, VGA crt controller register 0x3b4/0x3d4: 0x%02x\n",
1958 /* General Register - Input status 1 (MDA) */
1960 /* General Register - Input status 1 (CGA) */
1963 * Read from this register resets register 0x3c0 address flip-flop.
1965 vga_address_3c0
= TRUE
;
1968 * Read from this register returns following bits:
1969 * xxxx1xxx = Vertical retrace in progress if set.
1970 * xxxxx1xx = Light pen switched on.
1971 * xxxxxx1x = Light pen trigger set.
1972 * xxxxxxx1 = Either vertical or horizontal retrace
1973 * in progress if set.
1976 if (vga_retrace_vertical
)
1978 if (vga_retrace_horizontal
)
1982 * If VGA mode has been set, vertical retrace is
1983 * turned on once a frame and cleared after each read.
1984 * This might cause applications that synchronize with
1985 * vertical retrace to actually skip one frame but that
1986 * is probably not a problem.
1988 * If no VGA mode has been set, vertical retrace is faked
1989 * by toggling the value after every read.
1991 if (VGA_IsTimerRunning())
1992 vga_retrace_vertical
= FALSE
;
1994 vga_retrace_vertical
= !vga_retrace_vertical
;
1997 * Toggle horizontal retrace.
1999 vga_retrace_horizontal
= !vga_retrace_horizontal
;
2004 FIXME("Unsupported VGA register: 0x%04x\n", port
);
2009 void VGA_Clean(void)
2012 VGA_DeinstallTimer();