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 const VGA_MODE
*VGA_GetModeInfoList(void)
892 int VGA_SetMode(WORD mode
)
894 const VGA_MODE
*ModeInfo
;
895 /* get info on VGA mode & set appropriately */
896 VGA_CurrentMode
= mode
;
897 ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
899 /* check if mode is supported */
900 if (ModeInfo
->Supported
)
902 FIXME("Setting VGA mode %i - Supported mode - Improve reporting of missing capabilities for modes & modetypes.\n", mode
);
906 FIXME("Setting VGA mode %i - Unsupported mode - Will doubtfully work at all, but we'll try anyways.\n", mode
);
909 /* set up graphic or text display */
910 if (ModeInfo
->ModeType
== TEXT
)
912 VGA_SetAlphaMode(ModeInfo
->TextCols
, ModeInfo
->TextRows
);
916 return VGA_SetGraphicMode(mode
);
918 return 0; /* assume all good & return zero */
921 int VGA_SetGraphicMode(WORD mode
)
926 /* get info on VGA mode & set appropriately */
927 const VGA_MODE
*ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
928 /* check if we're assuming composite display */
929 if ((mode
== 6) && (CGA_ColorComposite
))
931 vga_fb_width
= (ModeInfo
->Width
/ 4);
932 vga_fb_height
= ModeInfo
->Height
;
933 vga_fb_depth
= (ModeInfo
->Depth
* 4);
937 vga_fb_width
= ModeInfo
->Width
;
938 vga_fb_height
= ModeInfo
->Height
;
939 vga_fb_depth
= ModeInfo
->Depth
;
942 vga_fb_pitch
= vga_fb_width
* ((vga_fb_depth
+ 7) / 8);
944 newSize
= vga_fb_width
* vga_fb_height
* ((vga_fb_depth
+ 7) / 8);
945 if(newSize
< 256 * 1024)
946 newSize
= 256 * 1024;
948 if(vga_fb_size
< newSize
) {
949 HeapFree(GetProcessHeap(), 0, vga_fb_data
);
950 vga_fb_data
= HeapAlloc(GetProcessHeap(), 0, newSize
);
951 vga_fb_size
= newSize
;
954 if(vga_fb_width
>= 640 || vga_fb_height
>= 480) {
955 par
.Xres
= vga_fb_width
;
956 par
.Yres
= vga_fb_height
;
963 if(vga_fb_depth
>= 8)
965 vga_fb_window_data
= VGA_WINDOW_START
;
966 vga_fb_window_size
= VGA_WINDOW_SIZE
;
967 vga_fb_palette
= vga_def_palette
;
968 vga_fb_palette_size
= 256;
972 vga_fb_window_data
= CGA_WINDOW_START
;
973 vga_fb_window_size
= CGA_WINDOW_SIZE
;
974 if(vga_fb_depth
== 2)
976 /* Select default 2 bit CGA palette */
977 vga_fb_palette
= cga_palette1
;
978 vga_fb_palette_size
= 4;
982 /* Top of VGA palette is same as 4 bit CGA palette */
983 vga_fb_palette
= vga_def_palette
;
984 vga_fb_palette_size
= 16;
987 vga_fb_palette_index
= 0;
991 /* Clean the HW buffer */
992 memset(vga_fb_window_data
, 0x00, vga_fb_window_size
);
994 /* Reset window start */
995 VGA_SetWindowStart(0);
997 par
.Depth
= (vga_fb_depth
< 8) ? 8 : vga_fb_depth
;
999 MZ_RunInThread(VGA_DoSetMode
, (ULONG_PTR
)&par
);
1003 int VGA_GetMode(unsigned*Height
,unsigned*Width
,unsigned*Depth
)
1005 if (!lpddraw
) return 1;
1006 if (!lpddsurf
) return 1;
1007 if (Height
) *Height
=sdesc
.dwHeight
;
1008 if (Width
) *Width
=sdesc
.dwWidth
;
1009 if (Depth
) *Depth
=sdesc
.ddpfPixelFormat
.u1
.dwRGBBitCount
;
1013 static void VGA_Exit(void)
1015 if (lpddraw
) MZ_RunInThread(VGA_DoExit
, 0);
1018 void VGA_SetPalette(PALETTEENTRY
*pal
,int start
,int len
)
1020 if (!lpddraw
) return;
1021 IDirectDrawPalette_SetEntries(lpddpal
,0,start
,len
,pal
);
1024 /* set a single [char wide] color in 16 color mode. */
1025 void VGA_SetColor16(int reg
,int color
)
1029 if (!lpddraw
) return;
1030 pal
= &vga_def64_palette
[color
];
1031 IDirectDrawPalette_SetEntries(lpddpal
,0,reg
,1,pal
);
1032 vga_16_palette
[reg
]=(char)color
;
1035 /* Get a single [char wide] color in 16 color mode. */
1036 char VGA_GetColor16(int reg
)
1039 if (!lpddraw
) return 0;
1040 return vga_16_palette
[reg
];
1043 /* set all 17 [char wide] colors at once in 16 color mode. */
1044 void VGA_Set16Palette(char *Table
)
1049 if (!lpddraw
) return; /* return if we're in text only mode */
1050 memcpy( Table
, vga_16_palette
, 17 ); /* copy the entries into the table */
1052 for (c
=0; c
<17; c
++) { /* 17 entries */
1053 pal
= &vga_def64_palette
[(int)vga_16_palette
[c
]]; /* get color */
1054 IDirectDrawPalette_SetEntries(lpddpal
,0,c
,1,pal
); /* set entry */
1055 TRACE("Palette register %d set to %d\n",c
,(int)vga_16_palette
[c
]);
1056 } /* end of the counting loop */
1059 /* Get all 17 [ char wide ] colors at once in 16 color mode. */
1060 void VGA_Get16Palette(char *Table
)
1063 if (!lpddraw
) return; /* return if we're in text only mode */
1064 memcpy( vga_16_palette
, Table
, 17 ); /* copy the entries into the table */
1067 static LPSTR
VGA_Lock(unsigned*Pitch
,unsigned*Height
,unsigned*Width
,unsigned*Depth
)
1069 if (!lpddraw
) return NULL
;
1070 if (!lpddsurf
) return NULL
;
1071 if (IDirectDrawSurface_Lock(lpddsurf
,NULL
,&sdesc
,0,0) != S_OK
) {
1072 ERR("could not lock surface!\n");
1075 if (Pitch
) *Pitch
=sdesc
.u1
.lPitch
;
1076 if (Height
) *Height
=sdesc
.dwHeight
;
1077 if (Width
) *Width
=sdesc
.dwWidth
;
1078 if (Depth
) *Depth
=sdesc
.ddpfPixelFormat
.u1
.dwRGBBitCount
;
1079 return sdesc
.lpSurface
;
1082 static void VGA_Unlock(void)
1084 IDirectDrawSurface_Unlock(lpddsurf
,sdesc
.lpSurface
);
1088 * Set start of 64k window at 0xa0000 in bytes.
1089 * If value is -1, initialize color plane support.
1090 * If value is >= 0, window contains direct copy of framebuffer.
1092 void VGA_SetWindowStart(int start
)
1094 if(start
== vga_fb_window
)
1097 EnterCriticalSection(&vga_lock
);
1099 if(vga_fb_window
== -1)
1100 FIXME("Remove VGA memory emulation.\n");
1102 VGA_SyncWindow( TRUE
);
1104 vga_fb_window
= start
;
1106 if(vga_fb_window
== -1)
1107 FIXME("Install VGA memory emulation.\n");
1109 VGA_SyncWindow( FALSE
);
1111 LeaveCriticalSection(&vga_lock
);
1115 * Get start of 64k window at 0xa0000 in bytes.
1116 * Value is -1 in color plane modes.
1118 int VGA_GetWindowStart(void)
1120 return vga_fb_window
;
1124 /**********************************************************************
1127 * Callback for VGA_ShowMouse.
1129 static void WINAPI
VGA_DoShowMouse( ULONG_PTR show
)
1135 rv
= ShowCursor( show
);
1137 while( show
? (rv
< 0) : (rv
>= 0) );
1141 /**********************************************************************
1144 * If argument is TRUE, unconditionally show mouse cursor.
1145 * If argument is FALSE, unconditionally hide mouse cursor.
1146 * This only works in graphics mode.
1148 void VGA_ShowMouse( BOOL show
)
1151 MZ_RunInThread( VGA_DoShowMouse
, (ULONG_PTR
)show
);
1155 /**********************************************************************
1158 * Update the current palette
1160 * Note: When updating the current CGA palette, palette index 0
1161 * refers to palette2, and index 1 is palette1 (default palette)
1163 void VGA_UpdatePalette(void)
1165 /* Figure out which palette is used now */
1166 if(vga_fb_bright
== TRUE
)
1168 if(vga_fb_palette_index
== 0)
1170 vga_fb_palette
= cga_palette2_bright
;
1172 else if(vga_fb_palette_index
== 1)
1174 vga_fb_palette
= cga_palette1_bright
;
1179 if(vga_fb_palette_index
== 0)
1181 vga_fb_palette
= cga_palette2
;
1183 else if(vga_fb_palette_index
== 1)
1185 vga_fb_palette
= cga_palette1
;
1189 /* Now update the palette */
1190 VGA_SetPalette(vga_fb_palette
,0,4);
1193 /**********************************************************************
1196 * Select if using a "bright" palette or not.
1197 * This is a property of the CGA controller
1199 void VGA_SetBright(BOOL bright
)
1201 TRACE("%i\n", bright
);
1203 /* Remember the "bright" value used by the CGA controller */
1204 vga_fb_bright
= bright
;
1207 /**********************************************************************
1210 * Select if output is enabled or disabled
1211 * This is a property of the CGA controller
1213 static void VGA_SetEnabled(BOOL enabled
)
1215 TRACE("%i\n", enabled
);
1217 /* Check if going from enabled to disabled */
1218 if(vga_fb_enabled
== TRUE
&& enabled
== FALSE
)
1220 /* Clear frame buffer */
1221 memset(vga_fb_window_data
, 0x00, vga_fb_window_size
);
1224 /* Remember the "enabled" value */
1225 vga_fb_enabled
= enabled
;
1228 /**********************************************************************
1229 * VGA_SetPaletteIndex
1231 * Select the index of the palette which is currently in use
1232 * This is a property of the CGA controller
1234 void VGA_SetPaletteIndex(unsigned index
)
1236 TRACE("%i\n", index
);
1238 /* Remember the palette index, which is only used by CGA for now */
1239 vga_fb_palette_index
= index
;
1242 /**********************************************************************
1245 * Write data to the framebuffer
1246 * This is a property of the CGA controller, but might be supported
1247 * later by other framebuffer types
1249 void VGA_WritePixel(unsigned color
, unsigned page
, unsigned col
, unsigned row
)
1255 /* Calculate CGA byte offset */
1256 char *data
= vga_fb_window_data
;
1257 off
= row
& 1 ? (8 * 1024) : 0;
1258 off
+= (80 * (row
/2));
1261 /* Calculate bits offset */
1262 pos
= 6 - (col
%4 * 2);
1264 /* Clear current data */
1269 bits
= color
<< pos
;
1275 /* prepare the text mode video memory copy that is used to only
1276 * update the video memory line that did get updated. */
1277 static void VGA_PrepareVideoMemCopy(unsigned Xres
, unsigned Yres
)
1283 * Allocate space for char + attr.
1287 vga_text_old
= HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1288 vga_text_old
, Xres
* Yres
* 2 );
1290 vga_text_old
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
1292 p
= VGA_AlphaBuffer();
1295 /* make sure the video mem copy contains the exact opposite of our
1296 * actual text mode memory area to make sure the screen
1297 * does get updated fully initially */
1298 for (i
=0; i
< Xres
*Yres
*2; i
++)
1299 *p2
++ = *p
++ ^ 0xff; /* XOR it */
1302 /**********************************************************************
1305 * Set VGA emulation to text mode.
1307 void VGA_SetAlphaMode(unsigned Xres
,unsigned Yres
)
1310 VGA_DeinstallTimer();
1312 VGA_PrepareVideoMemCopy(Xres
, Yres
);
1313 vga_text_width
= Xres
;
1314 vga_text_height
= Yres
;
1316 if (vga_text_x
>= vga_text_width
|| vga_text_y
>= vga_text_height
)
1317 VGA_SetCursorPos(0,0);
1319 if(vga_text_console
) {
1323 SetConsoleScreenBufferSize( VGA_AlphaConsole(), size
);
1325 /* poll every 30ms (33fps should provide adequate responsiveness) */
1326 VGA_InstallTimer(30);
1330 /**********************************************************************
1333 * Initialize VGA text mode handling and return default text mode.
1334 * This function does not set VGA emulation to text mode.
1336 void VGA_InitAlphaMode(unsigned*Xres
,unsigned*Yres
)
1338 CONSOLE_SCREEN_BUFFER_INFO info
;
1340 if(GetConsoleScreenBufferInfo( VGA_AlphaConsole(), &info
))
1342 vga_text_console
= TRUE
;
1343 vga_text_x
= info
.dwCursorPosition
.X
;
1344 vga_text_y
= info
.dwCursorPosition
.Y
;
1345 vga_text_attr
= info
.wAttributes
;
1346 *Xres
= info
.dwSize
.X
;
1347 *Yres
= info
.dwSize
.Y
;
1351 vga_text_console
= FALSE
;
1354 vga_text_attr
= 0x0f;
1360 /**********************************************************************
1363 * Get current text mode. Returns TRUE and sets resolution if
1364 * any VGA text mode has been initialized.
1366 BOOL
VGA_GetAlphaMode(unsigned*Xres
,unsigned*Yres
)
1368 if (vga_text_width
!= 0 && vga_text_height
!= 0) {
1369 *Xres
= vga_text_width
;
1370 *Yres
= vga_text_height
;
1376 void VGA_SetCursorShape(unsigned char start_options
, unsigned char end
)
1378 CONSOLE_CURSOR_INFO cci
;
1380 /* standard cursor settings:
1381 * 0x0607 == CGA, 0x0b0c == monochrome, 0x0d0e == EGA/VGA */
1383 /* calculate percentage from bottom - assuming VGA (bottom 0x0e) */
1384 cci
.dwSize
= ((end
& 0x1f) - (start_options
& 0x1f))/0x0e * 100;
1385 if (!cci
.dwSize
) cci
.dwSize
++; /* NULL cursor would make SCCI() fail ! */
1386 cci
.bVisible
= ((start_options
& 0x60) != 0x20); /* invisible ? */
1388 SetConsoleCursorInfo(VGA_AlphaConsole(),&cci
);
1391 void VGA_SetCursorPos(unsigned X
,unsigned Y
)
1397 void VGA_GetCursorPos(unsigned*X
,unsigned*Y
)
1399 if (X
) *X
= vga_text_x
;
1400 if (Y
) *Y
= vga_text_y
;
1403 static void VGA_PutCharAt(unsigned x
, unsigned y
, BYTE ascii
, int attr
)
1405 const VGA_MODE
*ModeInfo
= VGA_GetModeInfo(VGA_CurrentMode
);
1406 if ( ModeInfo
->ModeType
== TEXT
)
1408 char *dat
= VGA_AlphaBuffer() + ((vga_text_width
* y
+ x
) * 2);
1415 FIXME("Write %c at (%i,%i) - not yet supported in graphic modes.\n", (char)ascii
, x
, y
);
1419 void VGA_WriteChars(unsigned X
,unsigned Y
,unsigned ch
,int attr
,int count
)
1421 EnterCriticalSection(&vga_lock
);
1424 VGA_PutCharAt(X
+ count
, Y
, ch
, attr
);
1426 LeaveCriticalSection(&vga_lock
);
1429 void VGA_PutChar(BYTE ascii
)
1433 EnterCriticalSection(&vga_lock
);
1440 VGA_PutCharAt(vga_text_x
, vga_text_y
, ' ', 0);
1445 vga_text_x
+= ((vga_text_x
+ 8) & ~7) - vga_text_x
;
1461 VGA_PutCharAt(vga_text_x
, vga_text_y
, ascii
, vga_text_attr
);
1465 if (vga_text_x
>= vga_text_width
)
1471 if (vga_text_y
>= vga_text_height
)
1473 vga_text_y
= vga_text_height
- 1;
1474 VGA_ScrollUpText( 0, 0,
1475 vga_text_height
- 1, vga_text_width
- 1,
1480 * If we don't have a console, write directly to standard output.
1482 if(!vga_text_console
)
1483 WriteFile(VGA_AlphaConsole(), &ascii
, 1, &w
, NULL
);
1485 LeaveCriticalSection(&vga_lock
);
1488 void VGA_ClearText(unsigned row1
, unsigned col1
,
1489 unsigned row2
, unsigned col2
,
1494 EnterCriticalSection(&vga_lock
);
1496 for(y
=row1
; y
<=row2
; y
++)
1497 for(x
=col1
; x
<=col2
; x
++)
1498 VGA_PutCharAt(x
, y
, 0x20, attr
);
1500 LeaveCriticalSection(&vga_lock
);
1503 void VGA_ScrollUpText(unsigned row1
, unsigned col1
,
1504 unsigned row2
, unsigned col2
,
1505 unsigned lines
, BYTE attr
)
1507 char *buffer
= VGA_AlphaBuffer();
1510 EnterCriticalSection(&vga_lock
);
1515 for (y
= row1
; y
<= row2
- lines
; y
++)
1516 memmove( buffer
+ col1
+ y
* vga_text_width
* 2,
1517 buffer
+ col1
+ (y
+ lines
) * vga_text_width
* 2,
1518 (col2
- col1
+ 1) * 2 );
1521 * Fill exposed lines.
1523 for (y
= max(row1
, row2
- lines
+ 1); y
<= row2
; y
++)
1524 VGA_WriteChars( col1
, y
, ' ', attr
, col2
- col1
+ 1 );
1526 LeaveCriticalSection(&vga_lock
);
1529 void VGA_ScrollDownText(unsigned row1
, unsigned col1
,
1530 unsigned row2
, unsigned col2
,
1531 unsigned lines
, BYTE attr
)
1533 char *buffer
= VGA_AlphaBuffer();
1536 EnterCriticalSection(&vga_lock
);
1541 for (y
= row2
; y
>= row1
+ lines
; y
--)
1542 memmove( buffer
+ col1
+ y
* vga_text_width
* 2,
1543 buffer
+ col1
+ (y
- lines
) * vga_text_width
* 2,
1544 (col2
- col1
+ 1) * 2 );
1547 * Fill exposed lines.
1549 for (y
= row1
; y
<= min(row1
+ lines
- 1, row2
); y
++)
1550 VGA_WriteChars( col1
, y
, ' ', attr
, col2
- col1
+ 1 );
1552 LeaveCriticalSection(&vga_lock
);
1555 void VGA_GetCharacterAtCursor(BYTE
*ascii
, BYTE
*attr
)
1559 dat
= VGA_AlphaBuffer() + ((vga_text_width
* vga_text_y
+ vga_text_x
) * 2);
1568 /* FIXME: optimize by doing this only if the data has actually changed
1569 * (in a way similar to DIBSection, perhaps) */
1570 static void VGA_Poll_Graphics(void)
1572 unsigned int Pitch
, Height
, Width
, X
, Y
;
1574 char *dat
= vga_fb_data
+ vga_fb_offset
;
1575 int bpp
= (vga_fb_depth
+ 7) / 8;
1577 surf
= VGA_Lock(&Pitch
,&Height
,&Width
,NULL
);
1581 * Synchronize framebuffer contents.
1583 if (vga_fb_window
!= -1)
1584 VGA_SyncWindow( TRUE
);
1587 * CGA framebuffer (160x200) - CGA_ColorComposite, special subtype of mode 6
1588 * This buffer is encoded as following:
1589 * - 4 bit pr. pixel, 2 pixels per byte
1590 * - 80 bytes per row
1591 * - Every second line has an offset of 8096
1593 if(vga_fb_depth
== 4 && vga_fb_width
== 160 && vga_fb_height
== 200){
1597 for(Y
=0; Y
<vga_fb_height
; Y
++, surf
+=(Pitch
*2)){
1598 for(X
=0; X
<vga_fb_width
; X
++){
1599 off
= Y
& 1 ? (8 * 1024) : 0;
1600 off
+= (80 * (Y
/2));
1602 value
= (dat
[off
] >> bits
) & 0xF;
1603 surf
[(X
*4)+0] = value
;
1604 surf
[(X
*4)+1] = value
;
1605 surf
[(X
*4)+2] = value
;
1606 surf
[(X
*4)+3] = value
;
1607 surf
[(X
*4)+Pitch
+0] = value
;
1608 surf
[(X
*4)+Pitch
+1] = value
;
1609 surf
[(X
*4)+Pitch
+2] = value
;
1610 surf
[(X
*4)+Pitch
+3] = value
;
1618 * CGA framebuffer (320x200)
1619 * This buffer is encoded as following:
1620 * - 2 bits per color, 4 pixels per byte
1621 * - 80 bytes per row
1622 * - Every second line has an offset of 8096
1624 else if(vga_fb_depth
== 2 && vga_fb_width
== 320 && vga_fb_height
== 200){
1629 for(Y
=0; Y
<vga_fb_height
; Y
++, surf
+=(Pitch
*2)){
1630 for(X
=0; X
<vga_fb_width
; X
++){
1631 off
= Y
& 1 ? (8 * 1024) : 0;
1632 off
+= (80 * (Y
/2));
1634 value
= (dat
[off
] >> bits
) & 0x3;
1635 surf
[(X
*2)] = value
;
1636 surf
[(X
*2)+1] = value
;
1637 surf
[(X
*2)+Pitch
] = value
;
1638 surf
[(X
*2)+Pitch
+1] = value
;
1646 * Double VGA framebuffer (320x200 -> 640x400), if needed.
1648 else if(Height
>= 2 * vga_fb_height
&& Width
>= 2 * vga_fb_width
&& bpp
== 1)
1649 for (Y
=0; Y
<vga_fb_height
; Y
++,surf
+=Pitch
*2,dat
+=vga_fb_pitch
)
1650 for (X
=0; X
<vga_fb_width
; X
++) {
1651 BYTE value
= dat
[X
];
1653 surf
[X
*2+1] = value
;
1654 surf
[X
*2+Pitch
] = value
;
1655 surf
[X
*2+Pitch
+1] = value
;
1658 * Linear Buffer, including mode 19
1661 for (Y
=0; Y
<vga_fb_height
; Y
++,surf
+=Pitch
,dat
+=vga_fb_pitch
)
1662 memcpy(surf
, dat
, vga_fb_width
* bpp
);
1667 static void VGA_Poll_Text(void)
1669 char *dat
, *old
, *p_line
;
1671 CHAR_INFO ch
[256]; /* that should suffice for the largest text width */
1674 HANDLE con
= VGA_AlphaConsole();
1675 BOOL linechanged
= FALSE
; /* video memory area differs from stored copy? */
1677 /* Synchronize cursor position. */
1680 SetConsoleCursorPosition(con
,off
);
1682 dat
= VGA_AlphaBuffer();
1683 old
= vga_text_old
; /* pointer to stored video mem copy */
1684 siz
.X
= vga_text_width
; siz
.Y
= 1;
1685 off
.X
= 0; off
.Y
= 0;
1687 /* copy from virtual VGA frame buffer to console */
1688 for (Y
=0; Y
<vga_text_height
; Y
++) {
1689 linechanged
= memcmp(dat
, old
, vga_text_width
*2);
1692 /*TRACE("line %d changed\n", Y);*/
1694 for (X
=0; X
<vga_text_width
; X
++) {
1695 ch
[X
].Char
.AsciiChar
= *p_line
++;
1696 /* WriteConsoleOutputA doesn't like "dead" chars */
1697 if (ch
[X
].Char
.AsciiChar
== '\0')
1698 ch
[X
].Char
.AsciiChar
= ' ';
1699 ch
[X
].Attributes
= *p_line
++;
1701 dest
.Top
=Y
; dest
.Bottom
=Y
;
1702 dest
.Left
=0; dest
.Right
=vga_text_width
+1;
1703 WriteConsoleOutputA(con
, ch
, siz
, off
, &dest
);
1704 memcpy(old
, dat
, vga_text_width
*2);
1706 /* advance to next text line */
1707 dat
+= vga_text_width
*2;
1708 old
+= vga_text_width
*2;
1712 static void CALLBACK
VGA_Poll( LPVOID arg
, DWORD low
, DWORD high
)
1714 EnterCriticalSection(&vga_lock
);
1717 VGA_Poll_Graphics();
1722 * Fake start of retrace.
1724 vga_retrace_vertical
= TRUE
;
1726 LeaveCriticalSection(&vga_lock
);
1729 static BYTE palreg
,palcnt
;
1730 static PALETTEENTRY paldat
;
1732 void VGA_ioport_out( WORD port
, BYTE val
)
1735 /* General Register - Feature Control */
1737 FIXME("Unsupported VGA register: general register - feature control 0x%04x (value 0x%02x)\n", port
, val
);
1739 /* Attribute Controller - Address/Other */
1741 if (vga_address_3c0
)
1742 vga_index_3c0
= val
;
1744 FIXME("Unsupported index, VGA attribute controller register 0x3c0: 0x%02x (value 0x%02x)\n",
1745 vga_index_3c0
, val
);
1746 vga_address_3c0
= !vga_address_3c0
;
1748 /* General Register - Misc output */
1750 FIXME("Unsupported VGA register: general register - misc output 0x%04x (value 0x%02x)\n", port
, val
);
1752 /* General Register - Video subsystem enable */
1754 FIXME("Unsupported VGA register: general register - video subsystem enable 0x%04x (value 0x%02x)\n", port
, val
);
1756 /* Sequencer Register - Address */
1758 vga_index_3c4
= val
;
1760 /* Sequencer Register - Other */
1762 switch(vga_index_3c4
) {
1763 case 0x04: /* Sequencer: Memory Mode Register */
1764 if(vga_fb_depth
== 8)
1765 VGA_SetWindowStart((val
& 8) ? 0 : -1);
1767 FIXME("Memory Mode Register not supported in this mode.\n");
1770 FIXME("Unsupported index, VGA sequencer register 0x3c4: 0x%02x (value 0x%02x)\n",
1771 vga_index_3c4
, val
);
1775 palreg
=val
; palcnt
=0; break;
1777 ((BYTE
*)&paldat
)[palcnt
++]=val
<< 2;
1779 VGA_SetPalette(&paldat
,palreg
++,1);
1783 /* Graphics Controller Register - Address */
1785 vga_index_3ce
= val
;
1787 /* Graphics Controller Register - Other */
1789 FIXME("Unsupported index, VGA graphics controller register - other 0x3ce: 0x%02x (value 0x%02x)\n",
1790 vga_index_3ce
, val
);
1792 /* CRT Controller Register - Index (MDA) */
1794 /* CRT Controller Register - Index (CGA) */
1796 vga_index_3d4
= val
;
1798 /* CRT Controller Register - Other (MDA) */
1800 /* CRT Controller Register - Other (CGA) */
1802 FIXME("Unsupported index, VGA crt controller register 0x3b4/0x3d4: 0x%02x (value 0x%02x)\n",
1803 vga_index_3d4
, val
);
1805 /* Mode control register - 6845 Motorola (MDA) */
1807 /* Mode control register - 6845 Motorola (CGA) */
1810 * xxxxxxx1 = 80x25 text
1811 * xxxxxxx0 = 40x25 text (default)
1812 * xxxxxx1x = graphics (320x200)
1816 * xxxx1xxx = enable video signal
1817 * xxx1xxxx = 640x200 B/W graphics
1821 /* check bits 6 and 7 */
1824 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x - bits 7 and 6 not supported.\n", val
);
1826 /* check bits 5 - blink on */
1829 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x (bit 5) - blink is not supported.\n", val
);
1831 /* Enable Video Signal (bit 3) - Set the enabled bit */
1832 VGA_SetEnabled((val
& 0x08) && 1);
1834 /* xxx1x010 - Detect 160x200, 16 color mode (CGA composite) */
1835 if( (val
& 0x17) == 0x12 )
1837 /* Switch to 160x200x4 composite mode - special case of mode 6 */
1838 CGA_ColorComposite
= TRUE
;
1843 /* turn off composite colors otherwise, including 320x200 (80x200 16 color) */
1844 CGA_ColorComposite
= FALSE
;
1847 /* xxx0x100 - Detect VGA mode 0 */
1848 if( (val
& 0x17) == 0x04 )
1852 /* xxx0x000 - Detect VGA mode 1 */
1853 else if( (val
& 0x17) == 0x00 )
1857 /* xxx0x101 - Detect VGA mode 2 */
1858 else if( (val
& 0x17) == 0x05 )
1862 /* xxx0x001 - Detect VGA mode 3 */
1863 else if( (val
& 0x17) == 0x01 )
1867 /* xxx0x010 - Detect VGA mode 4 */
1868 else if( (val
& 0x17) == 0x02 )
1872 /* xxx0x110 - Detect VGA mode 5 */
1873 else if( (val
& 0x17) == 0x06 )
1877 /* xxx1x110 - Detect VGA mode 6 */
1878 else if( (val
& 0x17) == 0x16 )
1882 /* unsupported mode */
1885 FIXME("Unsupported value, VGA register 0x3d8: 0x%02x - unrecognized MDA/CGA mode\n", val
); /* Set the enabled bit */
1890 /* Colour control register (CGA) */
1893 VGA_SetBright((val
& 0x10) && 1);
1895 /* Set palette index */
1896 VGA_SetPaletteIndex((val
& 0x20) && 1);
1898 /* Now update the palette */
1899 VGA_UpdatePalette();
1902 FIXME("Unsupported VGA register: 0x%04x (value 0x%02x)\n", port
, val
);
1906 BYTE
VGA_ioport_in( WORD port
)
1911 /* Attribute Controller - Other */
1913 FIXME("Unsupported index, VGA attribute controller register 0x3c0: 0x%02x\n",
1916 /* General Register - Input status 0 */
1919 FIXME("Unsupported VGA register: general register - input status 0 0x%04x\n", port
);
1921 /* General Register - Video subsystem enable */
1924 FIXME("Unsupported VGA register: general register - video subsystem enable 0x%04x\n", port
);
1926 /* Sequencer Register - Other */
1928 switch(vga_index_3c4
) {
1929 case 0x04: /* Sequencer: Memory Mode Register */
1930 return (VGA_GetWindowStart() == -1) ? 0xf7 : 0xff;
1932 FIXME("Unsupported index, register 0x3c4: 0x%02x\n",
1936 /* General Register - DAC State */
1939 FIXME("Unsupported VGA register: general register - DAC State 0x%04x\n", port
);
1941 /* General Register - Feature control */
1944 FIXME("Unsupported VGA register: general register - Feature control 0x%04x\n", port
);
1946 /* General Register - Misc output */
1949 FIXME("Unsupported VGA register: general register - Feature control 0x%04x\n", port
);
1951 /* Graphics Controller Register - Other */
1953 FIXME("Unsupported index, register 0x3ce: 0x%02x\n",
1956 /* CRT Controller Register - Other (MDA) */
1958 /* CRT Controller Register - Other (CGA) */
1960 FIXME("Unsupported index, VGA crt controller register 0x3b4/0x3d4: 0x%02x\n",
1963 /* General Register - Input status 1 (MDA) */
1965 /* General Register - Input status 1 (CGA) */
1968 * Read from this register resets register 0x3c0 address flip-flop.
1970 vga_address_3c0
= TRUE
;
1973 * Read from this register returns following bits:
1974 * xxxx1xxx = Vertical retrace in progress if set.
1975 * xxxxx1xx = Light pen switched on.
1976 * xxxxxx1x = Light pen trigger set.
1977 * xxxxxxx1 = Either vertical or horizontal retrace
1978 * in progress if set.
1981 if (vga_retrace_vertical
)
1983 if (vga_retrace_horizontal
)
1987 * If VGA mode has been set, vertical retrace is
1988 * turned on once a frame and cleared after each read.
1989 * This might cause applications that synchronize with
1990 * vertical retrace to actually skip one frame but that
1991 * is probably not a problem.
1993 * If no VGA mode has been set, vertical retrace is faked
1994 * by toggling the value after every read.
1996 if (VGA_IsTimerRunning())
1997 vga_retrace_vertical
= FALSE
;
1999 vga_retrace_vertical
= !vga_retrace_vertical
;
2002 * Toggle horizontal retrace.
2004 vga_retrace_horizontal
= !vga_retrace_horizontal
;
2009 FIXME("Unsupported VGA register: 0x%04x\n", port
);
2014 void VGA_Clean(void)
2017 VGA_DeinstallTimer();