1998-11-01 13:51:47 +01:00
|
|
|
|
/*
|
|
|
|
|
* VGA hardware emulation
|
2002-06-01 01:06:46 +02:00
|
|
|
|
*
|
1998-11-01 13:51:47 +01:00
|
|
|
|
* Copyright 1998 Ove K<EFBFBD>ven (with some help from Marcus Meissner)
|
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1998-11-01 13:51:47 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include <stdarg.h>
|
1998-11-01 13:51:47 +01:00
|
|
|
|
#include <string.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include "windef.h"
|
1998-11-01 13:51:47 +01:00
|
|
|
|
#include "winbase.h"
|
2001-06-19 20:14:08 +02:00
|
|
|
|
#include "wingdi.h"
|
|
|
|
|
#include "winuser.h"
|
2000-02-03 01:46:29 +01:00
|
|
|
|
#include "wincon.h"
|
2001-12-04 20:54:44 +01:00
|
|
|
|
#include "dosexe.h"
|
1998-11-01 13:51:47 +01:00
|
|
|
|
#include "vga.h"
|
|
|
|
|
#include "ddraw.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
|
#include "wine/debug.h"
|
1998-11-01 13:51:47 +01:00
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
|
1998-11-01 13:51:47 +01:00
|
|
|
|
static IDirectDraw *lpddraw = NULL;
|
|
|
|
|
static IDirectDrawSurface *lpddsurf;
|
|
|
|
|
static IDirectDrawPalette *lpddpal;
|
|
|
|
|
static DDSURFACEDESC sdesc;
|
2003-01-28 01:16:15 +01:00
|
|
|
|
|
|
|
|
|
static BOOL vga_retrace_vertical;
|
|
|
|
|
static BOOL vga_retrace_horizontal;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
|
2003-08-25 02:53:35 +02:00
|
|
|
|
/*
|
|
|
|
|
* Size and location of VGA controller window to framebuffer.
|
|
|
|
|
*
|
|
|
|
|
* Note: We support only single window even though some
|
|
|
|
|
* controllers support two. This should not be changed unless
|
|
|
|
|
* there are programs that depend on having two windows.
|
|
|
|
|
*/
|
|
|
|
|
#define VGA_WINDOW_SIZE (64 * 1024)
|
|
|
|
|
#define VGA_WINDOW_START ((char *)0xa0000)
|
|
|
|
|
|
2002-07-30 01:28:52 +02:00
|
|
|
|
/*
|
|
|
|
|
* VGA controller memory is emulated using linear framebuffer.
|
|
|
|
|
* This frambuffer also acts as an interface
|
|
|
|
|
* between VGA controller emulation and DirectDraw.
|
|
|
|
|
*
|
|
|
|
|
* vga_fb_width: Display width in pixels. Can be modified when
|
|
|
|
|
* display mode is changed.
|
|
|
|
|
* vga_fb_height: Display height in pixels. Can be modified when
|
|
|
|
|
* display mode is changed.
|
|
|
|
|
* vga_fb_depth: Number of bits used to store single pixel color information.
|
|
|
|
|
* Each pixel uses (vga_fb_depth+7)/8 bytes because
|
|
|
|
|
* 1-16 color modes are mapped to 256 color mode.
|
|
|
|
|
* Can be modified when display mode is changed.
|
2002-07-30 01:51:57 +02:00
|
|
|
|
* vga_fb_pitch: How many bytes to add to pointer in order to move
|
2002-07-30 01:28:52 +02:00
|
|
|
|
* from one row to another. This is fixed in VGA modes,
|
|
|
|
|
* but can be modified in SVGA modes.
|
|
|
|
|
* vga_fb_offset: Offset added to framebuffer start address in order
|
|
|
|
|
* to find the display origin. Programs use this to do
|
|
|
|
|
* double buffering and to scroll display. The value can
|
|
|
|
|
* be modified in VGA and SVGA modes.
|
|
|
|
|
* vga_fb_size: How many bytes are allocated to framebuffer.
|
|
|
|
|
* VGA framebuffers are always larger than display size and
|
|
|
|
|
* SVGA framebuffers may also be.
|
|
|
|
|
* vga_fb_data: Pointer to framebuffer start.
|
2002-08-13 05:17:42 +02:00
|
|
|
|
* vga_fb_window: Offset of 64k window 0xa0000 in bytes from framebuffer start.
|
|
|
|
|
* This value is >= 0, if mode uses linear framebuffer and
|
|
|
|
|
* -1, if mode uses color planes. This value is fixed
|
|
|
|
|
* in all modes except 0x13 (256 color VGA) where
|
|
|
|
|
* 0 means normal mode and -1 means Mode-X (unchained mode).
|
2002-07-30 01:28:52 +02:00
|
|
|
|
*/
|
|
|
|
|
static int vga_fb_width;
|
|
|
|
|
static int vga_fb_height;
|
|
|
|
|
static int vga_fb_depth;
|
|
|
|
|
static int vga_fb_pitch;
|
|
|
|
|
static int vga_fb_offset;
|
|
|
|
|
static int vga_fb_size = 0;
|
2003-01-23 22:32:35 +01:00
|
|
|
|
static char *vga_fb_data = 0;
|
2002-08-13 05:17:42 +02:00
|
|
|
|
static int vga_fb_window = 0;
|
2002-07-30 01:28:52 +02:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/*
|
|
|
|
|
* VGA text mode data.
|
|
|
|
|
*
|
|
|
|
|
* vga_text_attr: Current active attribute.
|
|
|
|
|
* vga_text_old: Last data sent to console.
|
|
|
|
|
* This is used to optimize console updates.
|
|
|
|
|
* vga_text_width: Width of the text display in characters.
|
|
|
|
|
* vga_text_height: Height of the text display in characters.
|
|
|
|
|
* vga_text_x: Current cursor X-position. Starts from zero.
|
|
|
|
|
* vga_text_y: Current cursor Y-position. Starts from zero.
|
|
|
|
|
* vga_text_console: TRUE if stdout is console,
|
|
|
|
|
* FALSE if it is regular file.
|
|
|
|
|
*/
|
|
|
|
|
static BYTE vga_text_attr;
|
|
|
|
|
static char *vga_text_old = NULL;
|
|
|
|
|
static BYTE vga_text_width;
|
|
|
|
|
static BYTE vga_text_height;
|
|
|
|
|
static BYTE vga_text_x;
|
|
|
|
|
static BYTE vga_text_y;
|
|
|
|
|
static BOOL vga_text_console;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
2002-07-28 19:42:30 +02:00
|
|
|
|
/*
|
|
|
|
|
* VGA controller ports 0x3c0, 0x3c4, 0x3ce and 0x3d4 are
|
2002-07-30 01:51:57 +02:00
|
|
|
|
* indexed registers. These ports are used to select VGA controller
|
|
|
|
|
* subregister that can be written to or read from using ports 0x3c1,
|
2002-07-28 19:42:30 +02:00
|
|
|
|
* 0x3c5, 0x3cf or 0x3d5. Selected subregister indexes are
|
|
|
|
|
* stored in variables vga_index_*.
|
|
|
|
|
*
|
|
|
|
|
* Port 0x3c0 is special because it is both index and
|
|
|
|
|
* data-write register. Flip-flop vga_address_3c0 tells whether
|
|
|
|
|
* the port acts currently as an address register. Reading from port
|
|
|
|
|
* 0x3da resets the flip-flop to address mode.
|
|
|
|
|
*/
|
|
|
|
|
static BYTE vga_index_3c0;
|
|
|
|
|
static BYTE vga_index_3c4;
|
|
|
|
|
static BYTE vga_index_3ce;
|
2002-07-30 01:51:57 +02:00
|
|
|
|
static BYTE vga_index_3d4;
|
2002-07-28 19:42:30 +02:00
|
|
|
|
static BOOL vga_address_3c0 = TRUE;
|
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
/*
|
|
|
|
|
* This mutex is used to protect VGA state during asynchronous
|
|
|
|
|
* screen updates (see VGA_Poll). It makes sure that VGA state changes
|
|
|
|
|
* are atomic and the user interface is protected from flicker and
|
|
|
|
|
* corruption.
|
|
|
|
|
*
|
|
|
|
|
* The mutex actually serializes VGA operations and the screen update.
|
|
|
|
|
* Which means that whenever VGA_Poll occurs, application stalls if it
|
|
|
|
|
* tries to modify VGA state. This is not how real VGA adapters work,
|
|
|
|
|
* but it makes timing and correctness issues much easier to deal with.
|
|
|
|
|
*/
|
2003-08-13 01:50:54 +02:00
|
|
|
|
static CRITICAL_SECTION vga_lock;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &vga_lock,
|
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": vga_lock") }
|
2003-08-13 01:50:54 +02:00
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION vga_lock = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2002-01-29 03:46:43 +01:00
|
|
|
|
|
2002-02-02 19:42:11 +01:00
|
|
|
|
typedef HRESULT (WINAPI *DirectDrawCreateProc)(LPGUID,LPDIRECTDRAW *,LPUNKNOWN);
|
2001-01-05 04:44:40 +01:00
|
|
|
|
static DirectDrawCreateProc pDirectDrawCreate;
|
2000-03-17 17:58:10 +01:00
|
|
|
|
|
2002-03-23 19:48:53 +01:00
|
|
|
|
static void CALLBACK VGA_Poll( LPVOID arg, DWORD low, DWORD high );
|
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
|
static HWND vga_hwnd = NULL;
|
2002-05-17 02:09:35 +02:00
|
|
|
|
|
2002-03-20 01:55:05 +01:00
|
|
|
|
/*
|
|
|
|
|
* For simplicity, I'm creating a second palette.
|
|
|
|
|
* 16 color accesses will use these pointers and insert
|
|
|
|
|
* entries from the 64-color palette into the default
|
|
|
|
|
* palette. --Robert 'Admiral' Coeyman
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static char vga_16_palette[17]={
|
|
|
|
|
0x00, /* 0 - Black */
|
|
|
|
|
0x01, /* 1 - Blue */
|
|
|
|
|
0x02, /* 2 - Green */
|
|
|
|
|
0x03, /* 3 - Cyan */
|
|
|
|
|
0x04, /* 4 - Red */
|
|
|
|
|
0x05, /* 5 - Magenta */
|
|
|
|
|
0x14, /* 6 - Brown */
|
|
|
|
|
0x07, /* 7 - Light gray */
|
|
|
|
|
0x38, /* 8 - Dark gray */
|
|
|
|
|
0x39, /* 9 - Light blue */
|
|
|
|
|
0x3a, /* A - Light green */
|
|
|
|
|
0x3b, /* B - Light cyan */
|
|
|
|
|
0x3c, /* C - Light red */
|
|
|
|
|
0x3d, /* D - Light magenta */
|
|
|
|
|
0x3e, /* E - Yellow */
|
|
|
|
|
0x3f, /* F - White */
|
|
|
|
|
0x00 /* Border Color */
|
|
|
|
|
};
|
|
|
|
|
|
2001-11-07 21:54:08 +01:00
|
|
|
|
static PALETTEENTRY vga_def_palette[256]={
|
|
|
|
|
/* red green blue */
|
|
|
|
|
{0x00, 0x00, 0x00}, /* 0 - Black */
|
|
|
|
|
{0x00, 0x00, 0x80}, /* 1 - Blue */
|
|
|
|
|
{0x00, 0x80, 0x00}, /* 2 - Green */
|
|
|
|
|
{0x00, 0x80, 0x80}, /* 3 - Cyan */
|
|
|
|
|
{0x80, 0x00, 0x00}, /* 4 - Red */
|
|
|
|
|
{0x80, 0x00, 0x80}, /* 5 - Magenta */
|
|
|
|
|
{0x80, 0x80, 0x00}, /* 6 - Brown */
|
|
|
|
|
{0xC0, 0xC0, 0xC0}, /* 7 - Light gray */
|
|
|
|
|
{0x80, 0x80, 0x80}, /* 8 - Dark gray */
|
|
|
|
|
{0x00, 0x00, 0xFF}, /* 9 - Light blue */
|
|
|
|
|
{0x00, 0xFF, 0x00}, /* A - Light green */
|
|
|
|
|
{0x00, 0xFF, 0xFF}, /* B - Light cyan */
|
|
|
|
|
{0xFF, 0x00, 0x00}, /* C - Light red */
|
|
|
|
|
{0xFF, 0x00, 0xFF}, /* D - Light magenta */
|
|
|
|
|
{0xFF, 0xFF, 0x00}, /* E - Yellow */
|
|
|
|
|
{0xFF, 0xFF, 0xFF}, /* F - White */
|
|
|
|
|
{0,0,0} /* FIXME: a series of continuous rainbow hues should follow */
|
|
|
|
|
};
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
/*
|
|
|
|
|
* This palette is the dos default, converted from 18 bit color to 24.
|
2002-03-20 01:55:05 +01:00
|
|
|
|
* It contains only 64 entries of colors--all others are zeros.
|
|
|
|
|
* --Robert 'Admiral' Coeyman
|
|
|
|
|
*/
|
|
|
|
|
static PALETTEENTRY vga_def64_palette[256]={
|
|
|
|
|
/* red green blue */
|
|
|
|
|
{0x00, 0x00, 0x00}, /* 0x00 Black */
|
|
|
|
|
{0x00, 0x00, 0xaa}, /* 0x01 Blue */
|
|
|
|
|
{0x00, 0xaa, 0x00}, /* 0x02 Green */
|
|
|
|
|
{0x00, 0xaa, 0xaa}, /* 0x03 Cyan */
|
|
|
|
|
{0xaa, 0x00, 0x00}, /* 0x04 Red */
|
|
|
|
|
{0xaa, 0x00, 0xaa}, /* 0x05 Magenta */
|
|
|
|
|
{0xaa, 0xaa, 0x00}, /* 0x06 */
|
|
|
|
|
{0xaa, 0xaa, 0xaa}, /* 0x07 Light Gray */
|
|
|
|
|
{0x00, 0x00, 0x55}, /* 0x08 */
|
|
|
|
|
{0x00, 0x00, 0xff}, /* 0x09 */
|
|
|
|
|
{0x00, 0xaa, 0x55}, /* 0x0a */
|
|
|
|
|
{0x00, 0xaa, 0xff}, /* 0x0b */
|
|
|
|
|
{0xaa, 0x00, 0x55}, /* 0x0c */
|
|
|
|
|
{0xaa, 0x00, 0xff}, /* 0x0d */
|
|
|
|
|
{0xaa, 0xaa, 0x55}, /* 0x0e */
|
|
|
|
|
{0xaa, 0xaa, 0xff}, /* 0x0f */
|
|
|
|
|
{0x00, 0x55, 0x00}, /* 0x10 */
|
|
|
|
|
{0x00, 0x55, 0xaa}, /* 0x11 */
|
|
|
|
|
{0x00, 0xff, 0x00}, /* 0x12 */
|
|
|
|
|
{0x00, 0xff, 0xaa}, /* 0x13 */
|
|
|
|
|
{0xaa, 0x55, 0x00}, /* 0x14 Brown */
|
|
|
|
|
{0xaa, 0x55, 0xaa}, /* 0x15 */
|
|
|
|
|
{0xaa, 0xff, 0x00}, /* 0x16 */
|
|
|
|
|
{0xaa, 0xff, 0xaa}, /* 0x17 */
|
|
|
|
|
{0x00, 0x55, 0x55}, /* 0x18 */
|
|
|
|
|
{0x00, 0x55, 0xff}, /* 0x19 */
|
|
|
|
|
{0x00, 0xff, 0x55}, /* 0x1a */
|
|
|
|
|
{0x00, 0xff, 0xff}, /* 0x1b */
|
|
|
|
|
{0xaa, 0x55, 0x55}, /* 0x1c */
|
|
|
|
|
{0xaa, 0x55, 0xff}, /* 0x1d */
|
|
|
|
|
{0xaa, 0xff, 0x55}, /* 0x1e */
|
|
|
|
|
{0xaa, 0xff, 0xff}, /* 0x1f */
|
|
|
|
|
{0x55, 0x00, 0x00}, /* 0x20 */
|
|
|
|
|
{0x55, 0x00, 0xaa}, /* 0x21 */
|
|
|
|
|
{0x55, 0xaa, 0x00}, /* 0x22 */
|
|
|
|
|
{0x55, 0xaa, 0xaa}, /* 0x23 */
|
|
|
|
|
{0xff, 0x00, 0x00}, /* 0x24 */
|
|
|
|
|
{0xff, 0x00, 0xaa}, /* 0x25 */
|
|
|
|
|
{0xff, 0xaa, 0x00}, /* 0x26 */
|
|
|
|
|
{0xff, 0xaa, 0xaa}, /* 0x27 */
|
|
|
|
|
{0x55, 0x00, 0x55}, /* 0x28 */
|
|
|
|
|
{0x55, 0x00, 0xff}, /* 0x29 */
|
|
|
|
|
{0x55, 0xaa, 0x55}, /* 0x2a */
|
|
|
|
|
{0x55, 0xaa, 0xff}, /* 0x2b */
|
|
|
|
|
{0xff, 0x00, 0x55}, /* 0x2c */
|
|
|
|
|
{0xff, 0x00, 0xff}, /* 0x2d */
|
|
|
|
|
{0xff, 0xaa, 0x55}, /* 0x2e */
|
|
|
|
|
{0xff, 0xaa, 0xff}, /* 0x2f */
|
|
|
|
|
{0x55, 0x55, 0x00}, /* 0x30 */
|
|
|
|
|
{0x55, 0x55, 0xaa}, /* 0x31 */
|
|
|
|
|
{0x55, 0xff, 0x00}, /* 0x32 */
|
|
|
|
|
{0x55, 0xff, 0xaa}, /* 0x33 */
|
|
|
|
|
{0xff, 0x55, 0x00}, /* 0x34 */
|
|
|
|
|
{0xff, 0x55, 0xaa}, /* 0x35 */
|
|
|
|
|
{0xff, 0xff, 0x00}, /* 0x36 */
|
|
|
|
|
{0xff, 0xff, 0xaa}, /* 0x37 */
|
|
|
|
|
{0x55, 0x55, 0x55}, /* 0x38 Dark Gray */
|
|
|
|
|
{0x55, 0x55, 0xff}, /* 0x39 Light Blue */
|
|
|
|
|
{0x55, 0xff, 0x55}, /* 0x3a Light Green */
|
|
|
|
|
{0x55, 0xff, 0xff}, /* 0x3b Light Cyan */
|
|
|
|
|
{0xff, 0x55, 0x55}, /* 0x3c Light Red */
|
|
|
|
|
{0xff, 0x55, 0xff}, /* 0x3d Light Magenta */
|
|
|
|
|
{0xff, 0xff, 0x55}, /* 0x3e Yellow */
|
|
|
|
|
{0xff, 0xff, 0xff}, /* 0x3f White */
|
|
|
|
|
{0,0,0} /* The next 192 entries are all zeros */
|
|
|
|
|
};
|
|
|
|
|
|
2002-03-23 19:48:53 +01:00
|
|
|
|
static HANDLE VGA_timer;
|
|
|
|
|
static HANDLE VGA_timer_thread;
|
|
|
|
|
|
|
|
|
|
/* set the timer rate; called in the polling thread context */
|
|
|
|
|
static void CALLBACK set_timer_rate( ULONG_PTR arg )
|
|
|
|
|
{
|
|
|
|
|
LARGE_INTEGER when;
|
|
|
|
|
|
2004-01-23 02:51:33 +01:00
|
|
|
|
when.u.LowPart = when.u.HighPart = 0;
|
2002-03-23 19:48:53 +01:00
|
|
|
|
SetWaitableTimer( VGA_timer, &when, arg, VGA_Poll, 0, FALSE );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DWORD CALLBACK VGA_TimerThread( void *dummy )
|
|
|
|
|
{
|
2003-06-30 04:10:19 +02:00
|
|
|
|
for (;;) SleepEx( INFINITE, TRUE );
|
2008-08-11 00:44:31 +02:00
|
|
|
|
return 0;
|
2002-03-23 19:48:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-03 01:46:29 +01:00
|
|
|
|
static void VGA_DeinstallTimer(void)
|
|
|
|
|
{
|
2002-03-23 19:48:53 +01:00
|
|
|
|
if (VGA_timer_thread)
|
|
|
|
|
{
|
2003-02-20 00:27:01 +01:00
|
|
|
|
/*
|
|
|
|
|
* Make sure the update thread is not holding
|
|
|
|
|
* system resources when we kill it.
|
|
|
|
|
*
|
|
|
|
|
* Now, we only need to worry about update thread
|
|
|
|
|
* getting terminated while in EnterCriticalSection
|
|
|
|
|
* or WaitForMultipleObjectsEx.
|
|
|
|
|
*
|
|
|
|
|
* FIXME: Is this a problem?
|
|
|
|
|
*/
|
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
2002-03-23 19:48:53 +01:00
|
|
|
|
CancelWaitableTimer( VGA_timer );
|
|
|
|
|
CloseHandle( VGA_timer );
|
|
|
|
|
TerminateThread( VGA_timer_thread, 0 );
|
|
|
|
|
CloseHandle( VGA_timer_thread );
|
|
|
|
|
VGA_timer_thread = 0;
|
2003-02-20 00:27:01 +01:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Synchronize display. This makes sure that
|
|
|
|
|
* changes to display become visible even if program
|
|
|
|
|
* terminates before update thread had time to run.
|
|
|
|
|
*/
|
|
|
|
|
VGA_Poll( 0, 0, 0 );
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void VGA_InstallTimer(unsigned Rate)
|
|
|
|
|
{
|
2002-03-23 19:48:53 +01:00
|
|
|
|
if (!VGA_timer_thread)
|
|
|
|
|
{
|
|
|
|
|
VGA_timer = CreateWaitableTimerA( NULL, FALSE, NULL );
|
|
|
|
|
VGA_timer_thread = CreateThread( NULL, 0, VGA_TimerThread, NULL, 0, NULL );
|
|
|
|
|
}
|
|
|
|
|
QueueUserAPC( set_timer_rate, VGA_timer_thread, (ULONG_PTR)Rate );
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
static BOOL VGA_IsTimerRunning(void)
|
|
|
|
|
{
|
|
|
|
|
return VGA_timer_thread ? TRUE : FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 13:05:50 +02:00
|
|
|
|
static HANDLE VGA_AlphaConsole(void)
|
2000-02-03 01:46:29 +01:00
|
|
|
|
{
|
|
|
|
|
/* this assumes that no Win32 redirection has taken place, but then again,
|
|
|
|
|
* only 16-bit apps are likely to use this part of Wine... */
|
|
|
|
|
return GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 13:05:50 +02:00
|
|
|
|
static char*VGA_AlphaBuffer(void)
|
2000-05-23 23:14:11 +02:00
|
|
|
|
{
|
2002-08-30 02:03:25 +02:00
|
|
|
|
return (char *)0xb8000;
|
2000-05-23 23:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2000-02-03 01:46:29 +01:00
|
|
|
|
/*** GRAPHICS MODE ***/
|
1998-11-01 13:51:47 +01:00
|
|
|
|
|
2001-11-07 21:54:08 +01:00
|
|
|
|
typedef struct {
|
|
|
|
|
unsigned Xres, Yres, Depth;
|
|
|
|
|
int ret;
|
|
|
|
|
} ModeSet;
|
|
|
|
|
|
2003-08-30 00:13:11 +02:00
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_SyncWindow
|
|
|
|
|
*
|
|
|
|
|
* Copy VGA window into framebuffer (if argument is TRUE) or
|
|
|
|
|
* part of framebuffer into VGA window (if argument is FALSE).
|
|
|
|
|
*/
|
|
|
|
|
static void VGA_SyncWindow( BOOL target_is_fb )
|
|
|
|
|
{
|
|
|
|
|
int size = VGA_WINDOW_SIZE;
|
|
|
|
|
|
|
|
|
|
/* Window does not overlap framebuffer. */
|
|
|
|
|
if (vga_fb_window >= vga_fb_size)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Check if window overlaps framebuffer only partially. */
|
|
|
|
|
if (vga_fb_size - vga_fb_window < VGA_WINDOW_SIZE)
|
|
|
|
|
size = vga_fb_size - vga_fb_window;
|
|
|
|
|
|
|
|
|
|
if (target_is_fb)
|
|
|
|
|
memmove( vga_fb_data + vga_fb_window, VGA_WINDOW_START, size );
|
|
|
|
|
else
|
|
|
|
|
memmove( VGA_WINDOW_START, vga_fb_data + vga_fb_window, size );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-05-12 01:00:17 +02:00
|
|
|
|
static void WINAPI VGA_DoExit(ULONG_PTR arg)
|
|
|
|
|
{
|
|
|
|
|
VGA_DeinstallTimer();
|
|
|
|
|
IDirectDrawSurface_SetPalette(lpddsurf,NULL);
|
|
|
|
|
IDirectDrawSurface_Release(lpddsurf);
|
|
|
|
|
lpddsurf=NULL;
|
|
|
|
|
IDirectDrawPalette_Release(lpddpal);
|
|
|
|
|
lpddpal=NULL;
|
|
|
|
|
IDirectDraw_Release(lpddraw);
|
|
|
|
|
lpddraw=NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 21:54:08 +01:00
|
|
|
|
static void WINAPI VGA_DoSetMode(ULONG_PTR arg)
|
1998-11-01 13:51:47 +01:00
|
|
|
|
{
|
2001-06-19 20:14:08 +02:00
|
|
|
|
LRESULT res;
|
2001-11-07 21:54:08 +01:00
|
|
|
|
ModeSet *par = (ModeSet *)arg;
|
|
|
|
|
par->ret=1;
|
2001-06-19 20:14:08 +02:00
|
|
|
|
|
2002-05-14 05:57:26 +02:00
|
|
|
|
if (lpddraw) VGA_DoExit(0);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
if (!lpddraw) {
|
2000-03-17 17:58:10 +01:00
|
|
|
|
if (!pDirectDrawCreate)
|
|
|
|
|
{
|
|
|
|
|
HMODULE hmod = LoadLibraryA( "ddraw.dll" );
|
2001-01-05 04:44:40 +01:00
|
|
|
|
if (hmod) pDirectDrawCreate = (DirectDrawCreateProc)GetProcAddress( hmod, "DirectDrawCreate" );
|
2001-06-19 20:14:08 +02:00
|
|
|
|
if (!pDirectDrawCreate) {
|
|
|
|
|
ERR("Can't lookup DirectDrawCreate from ddraw.dll.\n");
|
2001-11-07 21:54:08 +01:00
|
|
|
|
return;
|
2001-06-19 20:14:08 +02:00
|
|
|
|
}
|
2000-03-17 17:58:10 +01:00
|
|
|
|
}
|
2001-06-19 20:14:08 +02:00
|
|
|
|
res = pDirectDrawCreate(NULL,&lpddraw,NULL);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
if (!lpddraw) {
|
2001-06-19 20:14:08 +02:00
|
|
|
|
ERR("DirectDraw is not available (res = %lx)\n",res);
|
2001-11-07 21:54:08 +01:00
|
|
|
|
return;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
2002-05-17 02:09:35 +02:00
|
|
|
|
if (!vga_hwnd) {
|
2003-07-08 23:11:52 +02:00
|
|
|
|
vga_hwnd = CreateWindowExA(0,"STATIC","WINEDOS VGA",
|
|
|
|
|
WS_POPUP|WS_VISIBLE|SS_NOTIFY,0,0,
|
|
|
|
|
par->Xres,par->Yres,0,0,0,NULL);
|
2002-05-17 02:09:35 +02:00
|
|
|
|
if (!vga_hwnd) {
|
|
|
|
|
ERR("Failed to create user window.\n");
|
|
|
|
|
IDirectDraw_Release(lpddraw);
|
|
|
|
|
lpddraw=NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
SetWindowPos(vga_hwnd,0,0,0,par->Xres,par->Yres,SWP_NOMOVE|SWP_NOZORDER);
|
|
|
|
|
|
|
|
|
|
if ((res=IDirectDraw_SetCooperativeLevel(lpddraw,vga_hwnd,DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE))) {
|
2001-06-19 20:14:08 +02:00
|
|
|
|
ERR("Could not set cooperative level to exclusive (%lx)\n",res);
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 21:54:08 +01:00
|
|
|
|
if ((res=IDirectDraw_SetDisplayMode(lpddraw,par->Xres,par->Yres,par->Depth))) {
|
|
|
|
|
ERR("DirectDraw does not support requested display mode (%dx%dx%d), res = %lx!\n",par->Xres,par->Yres,par->Depth,res);
|
1999-03-27 17:49:55 +01:00
|
|
|
|
IDirectDraw_Release(lpddraw);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
lpddraw=NULL;
|
2001-11-07 21:54:08 +01:00
|
|
|
|
return;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
2001-11-07 21:54:08 +01:00
|
|
|
|
|
2001-06-19 20:14:08 +02:00
|
|
|
|
res=IDirectDraw_CreatePalette(lpddraw,DDPCAPS_8BIT,NULL,&lpddpal,NULL);
|
2001-11-07 21:54:08 +01:00
|
|
|
|
if (res) {
|
2001-06-19 20:14:08 +02:00
|
|
|
|
ERR("Could not create palette (res = %lx)\n",res);
|
2001-11-07 21:54:08 +01:00
|
|
|
|
IDirectDraw_Release(lpddraw);
|
|
|
|
|
lpddraw=NULL;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ((res=IDirectDrawPalette_SetEntries(lpddpal,0,0,256,vga_def_palette))) {
|
|
|
|
|
ERR("Could not set default palette entries (res = %lx)\n", res);
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-01 13:51:47 +01:00
|
|
|
|
memset(&sdesc,0,sizeof(sdesc));
|
|
|
|
|
sdesc.dwSize=sizeof(sdesc);
|
1999-01-17 17:55:11 +01:00
|
|
|
|
sdesc.dwFlags = DDSD_CAPS;
|
|
|
|
|
sdesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
1999-03-27 17:49:55 +01:00
|
|
|
|
if (IDirectDraw_CreateSurface(lpddraw,&sdesc,&lpddsurf,NULL)||(!lpddsurf)) {
|
1999-06-26 21:09:08 +02:00
|
|
|
|
ERR("DirectDraw surface is not available\n");
|
1999-03-27 17:49:55 +01:00
|
|
|
|
IDirectDraw_Release(lpddraw);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
lpddraw=NULL;
|
2001-11-07 21:54:08 +01:00
|
|
|
|
return;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
2000-05-23 23:14:11 +02:00
|
|
|
|
IDirectDrawSurface_SetPalette(lpddsurf,lpddpal);
|
2003-01-28 01:16:15 +01:00
|
|
|
|
vga_retrace_vertical = vga_retrace_horizontal = FALSE;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
/* poll every 20ms (50fps should provide adequate responsiveness) */
|
2000-05-10 06:43:32 +02:00
|
|
|
|
VGA_InstallTimer(20);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
2001-11-07 21:54:08 +01:00
|
|
|
|
par->ret=0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VGA_SetMode(unsigned Xres,unsigned Yres,unsigned Depth)
|
|
|
|
|
{
|
|
|
|
|
ModeSet par;
|
2002-07-30 01:28:52 +02:00
|
|
|
|
int newSize;
|
|
|
|
|
|
|
|
|
|
vga_fb_width = Xres;
|
|
|
|
|
vga_fb_height = Yres;
|
|
|
|
|
vga_fb_depth = Depth;
|
|
|
|
|
vga_fb_offset = 0;
|
|
|
|
|
vga_fb_pitch = Xres * ((Depth + 7) / 8);
|
|
|
|
|
|
|
|
|
|
newSize = Xres * Yres * ((Depth + 7) / 8);
|
|
|
|
|
if(newSize < 256 * 1024)
|
|
|
|
|
newSize = 256 * 1024;
|
|
|
|
|
|
|
|
|
|
if(vga_fb_size < newSize) {
|
2004-12-23 18:06:43 +01:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, vga_fb_data);
|
2002-07-30 01:28:52 +02:00
|
|
|
|
vga_fb_data = HeapAlloc(GetProcessHeap(), 0, newSize);
|
|
|
|
|
vga_fb_size = newSize;
|
|
|
|
|
}
|
2002-01-29 03:46:43 +01:00
|
|
|
|
|
|
|
|
|
if(Xres >= 640 || Yres >= 480) {
|
|
|
|
|
par.Xres = Xres;
|
|
|
|
|
par.Yres = Yres;
|
|
|
|
|
} else {
|
|
|
|
|
par.Xres = 640;
|
|
|
|
|
par.Yres = 480;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-13 05:17:42 +02:00
|
|
|
|
VGA_SetWindowStart((Depth < 8) ? -1 : 0);
|
|
|
|
|
|
2002-01-29 03:46:43 +01:00
|
|
|
|
par.Depth = (Depth < 8) ? 8 : Depth;
|
|
|
|
|
|
2001-12-04 20:54:44 +01:00
|
|
|
|
MZ_RunInThread(VGA_DoSetMode, (ULONG_PTR)&par);
|
2001-11-07 21:54:08 +01:00
|
|
|
|
return par.ret;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VGA_GetMode(unsigned*Height,unsigned*Width,unsigned*Depth)
|
|
|
|
|
{
|
|
|
|
|
if (!lpddraw) return 1;
|
|
|
|
|
if (!lpddsurf) return 1;
|
|
|
|
|
if (Height) *Height=sdesc.dwHeight;
|
|
|
|
|
if (Width) *Width=sdesc.dwWidth;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
if (Depth) *Depth=sdesc.ddpfPixelFormat.u1.dwRGBBitCount;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-05 13:05:50 +02:00
|
|
|
|
static void VGA_Exit(void)
|
1998-11-01 13:51:47 +01:00
|
|
|
|
{
|
2001-12-04 20:54:44 +01:00
|
|
|
|
if (lpddraw) MZ_RunInThread(VGA_DoExit, 0);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VGA_SetPalette(PALETTEENTRY*pal,int start,int len)
|
|
|
|
|
{
|
|
|
|
|
if (!lpddraw) return;
|
1999-03-27 17:49:55 +01:00
|
|
|
|
IDirectDrawPalette_SetEntries(lpddpal,0,start,len,pal);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-14 05:57:26 +02:00
|
|
|
|
/* set a single [char wide] color in 16 color mode. */
|
2002-03-20 01:55:05 +01:00
|
|
|
|
void VGA_SetColor16(int reg,int color)
|
|
|
|
|
{
|
|
|
|
|
PALETTEENTRY *pal;
|
|
|
|
|
|
|
|
|
|
if (!lpddraw) return;
|
|
|
|
|
pal= &vga_def64_palette[color];
|
|
|
|
|
IDirectDrawPalette_SetEntries(lpddpal,0,reg,1,pal);
|
|
|
|
|
vga_16_palette[reg]=(char)color;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-14 05:57:26 +02:00
|
|
|
|
/* Get a single [char wide] color in 16 color mode. */
|
|
|
|
|
char VGA_GetColor16(int reg)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!lpddraw) return 0;
|
2008-01-24 22:41:43 +01:00
|
|
|
|
return vga_16_palette[reg];
|
2002-05-14 05:57:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set all 17 [char wide] colors at once in 16 color mode. */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
void VGA_Set16Palette(char *Table)
|
2002-05-14 05:57:26 +02:00
|
|
|
|
{
|
|
|
|
|
PALETTEENTRY *pal;
|
|
|
|
|
int c;
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
if (!lpddraw) return; /* return if we're in text only mode */
|
2008-07-11 22:58:38 +02:00
|
|
|
|
memcpy( Table, vga_16_palette, 17 ); /* copy the entries into the table */
|
2003-04-01 02:12:50 +02:00
|
|
|
|
|
2002-05-14 05:57:26 +02:00
|
|
|
|
for (c=0; c<17; c++) { /* 17 entries */
|
|
|
|
|
pal= &vga_def64_palette[(int)vga_16_palette[c]]; /* get color */
|
|
|
|
|
IDirectDrawPalette_SetEntries(lpddpal,0,c,1,pal); /* set entry */
|
|
|
|
|
TRACE("Palette register %d set to %d\n",c,(int)vga_16_palette[c]);
|
|
|
|
|
} /* end of the counting loop */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get all 17 [ char wide ] colors at once in 16 color mode. */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
void VGA_Get16Palette(char *Table)
|
2002-05-14 05:57:26 +02:00
|
|
|
|
{
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
if (!lpddraw) return; /* return if we're in text only mode */
|
2008-07-11 22:58:38 +02:00
|
|
|
|
memcpy( vga_16_palette, Table, 17 ); /* copy the entries into the table */
|
2002-05-14 05:57:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
1998-11-01 13:51:47 +01:00
|
|
|
|
void VGA_SetQuadPalette(RGBQUAD*color,int start,int len)
|
|
|
|
|
{
|
|
|
|
|
PALETTEENTRY pal[256];
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
if (!lpddraw) return;
|
|
|
|
|
for (c=0; c<len; c++) {
|
|
|
|
|
pal[c].peRed =color[c].rgbRed;
|
|
|
|
|
pal[c].peGreen=color[c].rgbGreen;
|
|
|
|
|
pal[c].peBlue =color[c].rgbBlue;
|
|
|
|
|
pal[c].peFlags=0;
|
|
|
|
|
}
|
1999-03-27 17:49:55 +01:00
|
|
|
|
IDirectDrawPalette_SetEntries(lpddpal,0,start,len,pal);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-02 15:38:45 +01:00
|
|
|
|
static LPSTR VGA_Lock(unsigned*Pitch,unsigned*Height,unsigned*Width,unsigned*Depth)
|
1998-11-01 13:51:47 +01:00
|
|
|
|
{
|
|
|
|
|
if (!lpddraw) return NULL;
|
|
|
|
|
if (!lpddsurf) return NULL;
|
1999-03-27 17:49:55 +01:00
|
|
|
|
if (IDirectDrawSurface_Lock(lpddsurf,NULL,&sdesc,0,0)) {
|
1999-06-26 21:09:08 +02:00
|
|
|
|
ERR("could not lock surface!\n");
|
1998-11-01 13:51:47 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
if (Pitch) *Pitch=sdesc.u1.lPitch;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
if (Height) *Height=sdesc.dwHeight;
|
|
|
|
|
if (Width) *Width=sdesc.dwWidth;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
if (Depth) *Depth=sdesc.ddpfPixelFormat.u1.dwRGBBitCount;
|
|
|
|
|
return sdesc.lpSurface;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-02 15:38:45 +01:00
|
|
|
|
static void VGA_Unlock(void)
|
1998-11-01 13:51:47 +01:00
|
|
|
|
{
|
2001-01-04 23:44:55 +01:00
|
|
|
|
IDirectDrawSurface_Unlock(lpddsurf,sdesc.lpSurface);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-13 05:17:42 +02:00
|
|
|
|
/*
|
|
|
|
|
* Set start of 64k window at 0xa0000 in bytes.
|
|
|
|
|
* If value is -1, initialize color plane support.
|
|
|
|
|
* If value is >= 0, window contains direct copy of framebuffer.
|
|
|
|
|
*/
|
|
|
|
|
void VGA_SetWindowStart(int start)
|
|
|
|
|
{
|
|
|
|
|
if(start == vga_fb_window)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
2002-08-13 05:17:42 +02:00
|
|
|
|
if(vga_fb_window == -1)
|
|
|
|
|
FIXME("Remove VGA memory emulation.\n");
|
2003-08-30 00:13:11 +02:00
|
|
|
|
else
|
|
|
|
|
VGA_SyncWindow( TRUE );
|
2002-08-13 05:17:42 +02:00
|
|
|
|
|
|
|
|
|
vga_fb_window = start;
|
|
|
|
|
|
|
|
|
|
if(vga_fb_window == -1)
|
|
|
|
|
FIXME("Install VGA memory emulation.\n");
|
2003-08-30 00:13:11 +02:00
|
|
|
|
else
|
|
|
|
|
VGA_SyncWindow( FALSE );
|
2003-02-11 23:19:27 +01:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
2002-08-13 05:17:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get start of 64k window at 0xa0000 in bytes.
|
|
|
|
|
* Value is -1 in color plane modes.
|
|
|
|
|
*/
|
2007-08-29 21:42:28 +02:00
|
|
|
|
int VGA_GetWindowStart(void)
|
2002-08-13 05:17:42 +02:00
|
|
|
|
{
|
|
|
|
|
return vga_fb_window;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-20 21:11:30 +02:00
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_DoShowMouse
|
|
|
|
|
*
|
|
|
|
|
* Callback for VGA_ShowMouse.
|
|
|
|
|
*/
|
2008-04-10 13:01:59 +02:00
|
|
|
|
static void WINAPI VGA_DoShowMouse( ULONG_PTR show )
|
2004-09-20 21:11:30 +02:00
|
|
|
|
{
|
|
|
|
|
INT rv;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
rv = ShowCursor( show );
|
|
|
|
|
}
|
|
|
|
|
while( show ? (rv < 0) : (rv >= 0) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_ShowMouse
|
|
|
|
|
*
|
|
|
|
|
* If argument is TRUE, unconditionally show mouse cursor.
|
|
|
|
|
* If argument is FALSE, unconditionally hide mouse cursor.
|
|
|
|
|
* This only works in graphics mode.
|
|
|
|
|
*/
|
|
|
|
|
void VGA_ShowMouse( BOOL show )
|
|
|
|
|
{
|
|
|
|
|
if (lpddraw)
|
|
|
|
|
MZ_RunInThread( VGA_DoShowMouse, (ULONG_PTR)show );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-03 01:46:29 +01:00
|
|
|
|
/*** TEXT MODE ***/
|
|
|
|
|
|
2002-07-03 03:13:17 +02:00
|
|
|
|
/* prepare the text mode video memory copy that is used to only
|
|
|
|
|
* update the video memory line that did get updated. */
|
2005-07-05 13:05:50 +02:00
|
|
|
|
static void VGA_PrepareVideoMemCopy(unsigned Xres, unsigned Yres)
|
2002-07-03 03:13:17 +02:00
|
|
|
|
{
|
|
|
|
|
char *p, *p2;
|
2004-09-22 04:46:38 +02:00
|
|
|
|
unsigned int i;
|
2002-07-03 03:13:17 +02:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/*
|
|
|
|
|
* Allocate space for char + attr.
|
|
|
|
|
*/
|
2002-07-03 03:13:17 +02:00
|
|
|
|
|
2003-10-09 21:49:05 +02:00
|
|
|
|
if (vga_text_old)
|
|
|
|
|
vga_text_old = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
|
vga_text_old, Xres * Yres * 2 );
|
|
|
|
|
else
|
|
|
|
|
vga_text_old = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
|
Xres * Yres * 2 );
|
2002-07-03 03:13:17 +02:00
|
|
|
|
p = VGA_AlphaBuffer();
|
2002-11-24 23:15:56 +01:00
|
|
|
|
p2 = vga_text_old;
|
2002-07-03 03:13:17 +02:00
|
|
|
|
|
|
|
|
|
/* make sure the video mem copy contains the exact opposite of our
|
|
|
|
|
* actual text mode memory area to make sure the screen
|
|
|
|
|
* does get updated fully initially */
|
|
|
|
|
for (i=0; i < Xres*Yres*2; i++)
|
2003-02-14 20:23:16 +01:00
|
|
|
|
*p2++ = *p++ ^ 0xff; /* XOR it */
|
2002-07-03 03:13:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_SetAlphaMode
|
|
|
|
|
*
|
|
|
|
|
* Set VGA emulation to text mode.
|
|
|
|
|
*/
|
|
|
|
|
void VGA_SetAlphaMode(unsigned Xres,unsigned Yres)
|
2000-02-03 01:46:29 +01:00
|
|
|
|
{
|
2002-11-24 23:15:56 +01:00
|
|
|
|
VGA_Exit();
|
|
|
|
|
VGA_DeinstallTimer();
|
|
|
|
|
|
|
|
|
|
VGA_PrepareVideoMemCopy(Xres, Yres);
|
|
|
|
|
vga_text_width = Xres;
|
|
|
|
|
vga_text_height = Yres;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
if (vga_text_x >= vga_text_width || vga_text_y >= vga_text_height)
|
|
|
|
|
VGA_SetCursorPos(0,0);
|
2000-02-03 01:46:29 +01:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
if(vga_text_console) {
|
|
|
|
|
COORD size;
|
|
|
|
|
size.X = Xres;
|
|
|
|
|
size.Y = Yres;
|
|
|
|
|
SetConsoleScreenBufferSize( VGA_AlphaConsole(), size );
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/* poll every 30ms (33fps should provide adequate responsiveness) */
|
|
|
|
|
VGA_InstallTimer(30);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-03 03:13:17 +02:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_InitAlphaMode
|
|
|
|
|
*
|
|
|
|
|
* Initialize VGA text mode handling and return default text mode.
|
|
|
|
|
* This function does not set VGA emulation to text mode.
|
|
|
|
|
*/
|
|
|
|
|
void VGA_InitAlphaMode(unsigned*Xres,unsigned*Yres)
|
|
|
|
|
{
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
if(GetConsoleScreenBufferInfo( VGA_AlphaConsole(), &info ))
|
|
|
|
|
{
|
|
|
|
|
vga_text_console = TRUE;
|
|
|
|
|
vga_text_x = info.dwCursorPosition.X;
|
|
|
|
|
vga_text_y = info.dwCursorPosition.Y;
|
|
|
|
|
vga_text_attr = info.wAttributes;
|
|
|
|
|
*Xres = info.dwSize.X;
|
|
|
|
|
*Yres = info.dwSize.Y;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vga_text_console = FALSE;
|
|
|
|
|
vga_text_x = 0;
|
|
|
|
|
vga_text_y = 0;
|
|
|
|
|
vga_text_attr = 0x0f;
|
|
|
|
|
*Xres = 80;
|
|
|
|
|
*Yres = 25;
|
|
|
|
|
}
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
/**********************************************************************
|
|
|
|
|
* VGA_GetAlphaMode
|
|
|
|
|
*
|
|
|
|
|
* Get current text mode. Returns TRUE and sets resolution if
|
|
|
|
|
* any VGA text mode has been initialized.
|
|
|
|
|
*/
|
2002-07-30 01:51:57 +02:00
|
|
|
|
BOOL VGA_GetAlphaMode(unsigned*Xres,unsigned*Yres)
|
2000-02-03 01:46:29 +01:00
|
|
|
|
{
|
2002-11-24 23:15:56 +01:00
|
|
|
|
if (vga_text_width != 0 && vga_text_height != 0) {
|
|
|
|
|
*Xres = vga_text_width;
|
|
|
|
|
*Yres = vga_text_height;
|
2002-07-30 01:51:57 +02:00
|
|
|
|
return TRUE;
|
2002-11-24 23:15:56 +01:00
|
|
|
|
} else
|
|
|
|
|
return FALSE;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-01 20:13:52 +02:00
|
|
|
|
void VGA_SetCursorShape(unsigned char start_options, unsigned char end)
|
|
|
|
|
{
|
|
|
|
|
CONSOLE_CURSOR_INFO cci;
|
|
|
|
|
|
|
|
|
|
/* standard cursor settings:
|
|
|
|
|
* 0x0607 == CGA, 0x0b0c == monochrome, 0x0d0e == EGA/VGA */
|
|
|
|
|
|
|
|
|
|
/* calculate percentage from bottom - assuming VGA (bottom 0x0e) */
|
2002-07-03 03:13:17 +02:00
|
|
|
|
cci.dwSize = ((end & 0x1f) - (start_options & 0x1f))/0x0e * 100;
|
2002-07-01 20:13:52 +02:00
|
|
|
|
if (!cci.dwSize) cci.dwSize++; /* NULL cursor would make SCCI() fail ! */
|
|
|
|
|
cci.bVisible = ((start_options & 0x60) != 0x20); /* invisible ? */
|
|
|
|
|
|
|
|
|
|
SetConsoleCursorInfo(VGA_AlphaConsole(),&cci);
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-03 01:46:29 +01:00
|
|
|
|
void VGA_SetCursorPos(unsigned X,unsigned Y)
|
|
|
|
|
{
|
2002-11-24 23:15:56 +01:00
|
|
|
|
vga_text_x = X;
|
|
|
|
|
vga_text_y = Y;
|
|
|
|
|
}
|
2001-11-07 21:54:08 +01:00
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
void VGA_GetCursorPos(unsigned*X,unsigned*Y)
|
|
|
|
|
{
|
|
|
|
|
if (X) *X = vga_text_x;
|
|
|
|
|
if (Y) *Y = vga_text_y;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
static void VGA_PutCharAt(unsigned x, unsigned y, BYTE ascii, int attr)
|
2000-02-03 01:46:29 +01:00
|
|
|
|
{
|
2003-02-11 23:19:27 +01:00
|
|
|
|
char *dat = VGA_AlphaBuffer() + ((vga_text_width * y + x) * 2);
|
2002-11-24 23:15:56 +01:00
|
|
|
|
dat[0] = ascii;
|
2003-02-11 23:19:27 +01:00
|
|
|
|
if (attr>=0)
|
|
|
|
|
dat[1] = attr;
|
2000-02-03 01:46:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-23 23:14:11 +02:00
|
|
|
|
void VGA_WriteChars(unsigned X,unsigned Y,unsigned ch,int attr,int count)
|
|
|
|
|
{
|
2002-04-08 22:11:28 +02:00
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
while (count--)
|
|
|
|
|
VGA_PutCharAt(X + count, Y, ch, attr);
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VGA_PutChar(BYTE ascii)
|
|
|
|
|
{
|
2004-12-22 19:38:31 +01:00
|
|
|
|
DWORD w;
|
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
|
|
|
|
switch(ascii) {
|
|
|
|
|
case '\b':
|
2003-02-14 20:23:16 +01:00
|
|
|
|
if (vga_text_x)
|
2004-08-14 02:49:39 +02:00
|
|
|
|
{
|
2003-02-14 20:23:16 +01:00
|
|
|
|
vga_text_x--;
|
2004-08-14 02:49:39 +02:00
|
|
|
|
VGA_PutCharAt(vga_text_x, vga_text_y, ' ', 0);
|
|
|
|
|
}
|
2003-02-14 20:23:16 +01:00
|
|
|
|
break;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
case '\t':
|
2003-02-14 20:23:16 +01:00
|
|
|
|
vga_text_x += ((vga_text_x + 8) & ~7) - vga_text_x;
|
|
|
|
|
break;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
case '\n':
|
2003-02-14 20:23:16 +01:00
|
|
|
|
vga_text_y++;
|
|
|
|
|
vga_text_x = 0;
|
|
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
case '\a':
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '\r':
|
2002-11-24 23:15:56 +01:00
|
|
|
|
vga_text_x = 0;
|
|
|
|
|
break;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
default:
|
2002-11-24 23:15:56 +01:00
|
|
|
|
VGA_PutCharAt(vga_text_x, vga_text_y, ascii, vga_text_attr);
|
|
|
|
|
vga_text_x++;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-07 05:16:34 +02:00
|
|
|
|
if (vga_text_x >= vga_text_width)
|
|
|
|
|
{
|
|
|
|
|
vga_text_x = 0;
|
|
|
|
|
vga_text_y++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vga_text_y >= vga_text_height)
|
|
|
|
|
{
|
|
|
|
|
vga_text_y = vga_text_height - 1;
|
|
|
|
|
VGA_ScrollUpText( 0, 0,
|
|
|
|
|
vga_text_height - 1, vga_text_width - 1,
|
|
|
|
|
1, vga_text_attr );
|
|
|
|
|
}
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
/*
|
2003-02-11 23:19:27 +01:00
|
|
|
|
* If we don't have a console, write directly to standard output.
|
2002-04-08 22:11:28 +02:00
|
|
|
|
*/
|
2003-02-11 23:19:27 +01:00
|
|
|
|
if(!vga_text_console)
|
2004-12-22 19:38:31 +01:00
|
|
|
|
WriteFile(VGA_AlphaConsole(), &ascii, 1, &w, NULL);
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VGA_SetTextAttribute(BYTE attr)
|
|
|
|
|
{
|
|
|
|
|
vga_text_attr = attr;
|
2000-05-23 23:14:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
void VGA_ClearText(unsigned row1, unsigned col1,
|
2003-02-11 23:19:27 +01:00
|
|
|
|
unsigned row2, unsigned col2,
|
|
|
|
|
BYTE attr)
|
2002-04-11 19:33:15 +02:00
|
|
|
|
{
|
2002-11-24 23:15:56 +01:00
|
|
|
|
unsigned x, y;
|
2002-04-11 19:33:15 +02:00
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
EnterCriticalSection(&vga_lock);
|
2002-04-11 19:33:15 +02:00
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
for(y=row1; y<=row2; y++)
|
2002-11-24 23:15:56 +01:00
|
|
|
|
for(x=col1; x<=col2; x++)
|
2003-02-14 20:23:16 +01:00
|
|
|
|
VGA_PutCharAt(x, y, 0x20, attr);
|
2002-04-11 19:33:15 +02:00
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-07 05:16:34 +02:00
|
|
|
|
void VGA_ScrollUpText(unsigned row1, unsigned col1,
|
|
|
|
|
unsigned row2, unsigned col2,
|
|
|
|
|
unsigned lines, BYTE attr)
|
2002-04-11 19:33:15 +02:00
|
|
|
|
{
|
2003-05-07 05:16:34 +02:00
|
|
|
|
char *buffer = VGA_AlphaBuffer();
|
|
|
|
|
unsigned y;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Scroll buffer.
|
|
|
|
|
*/
|
|
|
|
|
for (y = row1; y <= row2 - lines; y++)
|
|
|
|
|
memmove( buffer + col1 + y * vga_text_width * 2,
|
|
|
|
|
buffer + col1 + (y + lines) * vga_text_width * 2,
|
|
|
|
|
(col2 - col1 + 1) * 2 );
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fill exposed lines.
|
|
|
|
|
*/
|
|
|
|
|
for (y = max(row1, row2 - lines + 1); y <= row2; y++)
|
|
|
|
|
VGA_WriteChars( col1, y, ' ', attr, col2 - col1 + 1 );
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
2002-04-11 19:33:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2003-05-07 05:16:34 +02:00
|
|
|
|
void VGA_ScrollDownText(unsigned row1, unsigned col1,
|
|
|
|
|
unsigned row2, unsigned col2,
|
|
|
|
|
unsigned lines, BYTE attr)
|
2002-04-11 19:33:15 +02:00
|
|
|
|
{
|
2003-05-07 05:16:34 +02:00
|
|
|
|
char *buffer = VGA_AlphaBuffer();
|
|
|
|
|
unsigned y;
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection(&vga_lock);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Scroll buffer.
|
|
|
|
|
*/
|
|
|
|
|
for (y = row2; y >= row1 + lines; y--)
|
|
|
|
|
memmove( buffer + col1 + y * vga_text_width * 2,
|
|
|
|
|
buffer + col1 + (y - lines) * vga_text_width * 2,
|
|
|
|
|
(col2 - col1 + 1) * 2 );
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fill exposed lines.
|
|
|
|
|
*/
|
|
|
|
|
for (y = row1; y <= min(row1 + lines - 1, row2); y++)
|
|
|
|
|
VGA_WriteChars( col1, y, ' ', attr, col2 - col1 + 1 );
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
2002-04-11 19:33:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
void VGA_GetCharacterAtCursor(BYTE *ascii, BYTE *attr)
|
2002-04-11 19:33:15 +02:00
|
|
|
|
{
|
|
|
|
|
char *dat;
|
|
|
|
|
|
2002-11-24 23:15:56 +01:00
|
|
|
|
dat = VGA_AlphaBuffer() + ((vga_text_width * vga_text_y + vga_text_x) * 2);
|
2002-04-11 19:33:15 +02:00
|
|
|
|
|
|
|
|
|
*ascii = dat[0];
|
|
|
|
|
*attr = dat[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-03 01:46:29 +01:00
|
|
|
|
/*** CONTROL ***/
|
2002-07-30 01:51:57 +02:00
|
|
|
|
|
2002-07-03 03:13:17 +02:00
|
|
|
|
/* FIXME: optimize by doing this only if the data has actually changed
|
|
|
|
|
* (in a way similar to DIBSection, perhaps) */
|
2002-01-29 03:46:43 +01:00
|
|
|
|
static void VGA_Poll_Graphics(void)
|
|
|
|
|
{
|
|
|
|
|
unsigned int Pitch, Height, Width, X, Y;
|
|
|
|
|
char *surf;
|
2002-07-30 01:28:52 +02:00
|
|
|
|
char *dat = vga_fb_data + vga_fb_offset;
|
2002-07-30 01:51:57 +02:00
|
|
|
|
int bpp = (vga_fb_depth + 7) / 8;
|
2002-01-29 03:46:43 +01:00
|
|
|
|
|
|
|
|
|
surf = VGA_Lock(&Pitch,&Height,&Width,NULL);
|
|
|
|
|
if (!surf) return;
|
|
|
|
|
|
2002-07-30 01:28:52 +02:00
|
|
|
|
/*
|
|
|
|
|
* Synchronize framebuffer contents.
|
|
|
|
|
*/
|
2003-08-30 00:13:11 +02:00
|
|
|
|
if (vga_fb_window != -1)
|
|
|
|
|
VGA_SyncWindow( TRUE );
|
2002-07-30 01:28:52 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Double VGA framebuffer (320x200 -> 640x400), if needed.
|
|
|
|
|
*/
|
|
|
|
|
if(Height >= 2 * vga_fb_height && Width >= 2 * vga_fb_width && bpp == 1)
|
|
|
|
|
for (Y=0; Y<vga_fb_height; Y++,surf+=Pitch*2,dat+=vga_fb_pitch)
|
|
|
|
|
for (X=0; X<vga_fb_width; X++) {
|
|
|
|
|
BYTE value = dat[X];
|
|
|
|
|
surf[X*2] = value;
|
|
|
|
|
surf[X*2+1] = value;
|
|
|
|
|
surf[X*2+Pitch] = value;
|
|
|
|
|
surf[X*2+Pitch+1] = value;
|
2002-01-29 03:46:43 +01:00
|
|
|
|
}
|
2002-07-30 01:28:52 +02:00
|
|
|
|
else
|
|
|
|
|
for (Y=0; Y<vga_fb_height; Y++,surf+=Pitch,dat+=vga_fb_pitch)
|
|
|
|
|
memcpy(surf, dat, vga_fb_width * bpp);
|
2002-01-29 03:46:43 +01:00
|
|
|
|
|
|
|
|
|
VGA_Unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
static void VGA_Poll_Text(void)
|
1998-11-01 13:51:47 +01:00
|
|
|
|
{
|
2002-07-03 03:13:17 +02:00
|
|
|
|
char *dat, *old, *p_line;
|
2002-11-24 23:15:56 +01:00
|
|
|
|
unsigned int X, Y;
|
2002-07-03 03:13:17 +02:00
|
|
|
|
CHAR_INFO ch[256]; /* that should suffice for the largest text width */
|
2002-04-08 22:11:28 +02:00
|
|
|
|
COORD siz, off;
|
|
|
|
|
SMALL_RECT dest;
|
|
|
|
|
HANDLE con = VGA_AlphaConsole();
|
2003-02-11 23:19:27 +01:00
|
|
|
|
BOOL linechanged = FALSE; /* video memory area differs from stored copy? */
|
|
|
|
|
|
|
|
|
|
/* Synchronize cursor position. */
|
|
|
|
|
off.X = vga_text_x;
|
|
|
|
|
off.Y = vga_text_y;
|
|
|
|
|
SetConsoleCursorPosition(con,off);
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
|
|
|
|
dat = VGA_AlphaBuffer();
|
2002-11-24 23:15:56 +01:00
|
|
|
|
old = vga_text_old; /* pointer to stored video mem copy */
|
|
|
|
|
siz.X = vga_text_width; siz.Y = 1;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
off.X = 0; off.Y = 0;
|
2003-02-11 23:19:27 +01:00
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
/* copy from virtual VGA frame buffer to console */
|
2002-11-24 23:15:56 +01:00
|
|
|
|
for (Y=0; Y<vga_text_height; Y++) {
|
|
|
|
|
linechanged = memcmp(dat, old, vga_text_width*2);
|
2002-07-03 03:13:17 +02:00
|
|
|
|
if (linechanged)
|
|
|
|
|
{
|
|
|
|
|
/*TRACE("line %d changed\n", Y);*/
|
|
|
|
|
p_line = dat;
|
2002-11-24 23:15:56 +01:00
|
|
|
|
for (X=0; X<vga_text_width; X++) {
|
2002-07-03 03:13:17 +02:00
|
|
|
|
ch[X].Char.AsciiChar = *p_line++;
|
|
|
|
|
/* WriteConsoleOutputA doesn't like "dead" chars */
|
|
|
|
|
if (ch[X].Char.AsciiChar == '\0')
|
|
|
|
|
ch[X].Char.AsciiChar = ' ';
|
|
|
|
|
ch[X].Attributes = *p_line++;
|
|
|
|
|
}
|
|
|
|
|
dest.Top=Y; dest.Bottom=Y;
|
2002-11-24 23:15:56 +01:00
|
|
|
|
dest.Left=0; dest.Right=vga_text_width+1;
|
2002-07-03 03:13:17 +02:00
|
|
|
|
WriteConsoleOutputA(con, ch, siz, off, &dest);
|
2002-11-24 23:15:56 +01:00
|
|
|
|
memcpy(old, dat, vga_text_width*2);
|
2002-07-03 03:13:17 +02:00
|
|
|
|
}
|
|
|
|
|
/* advance to next text line */
|
2002-11-24 23:15:56 +01:00
|
|
|
|
dat += vga_text_width*2;
|
|
|
|
|
old += vga_text_width*2;
|
2002-04-08 22:11:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-11-01 13:51:47 +01:00
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
static void CALLBACK VGA_Poll( LPVOID arg, DWORD low, DWORD high )
|
|
|
|
|
{
|
2003-02-11 23:19:27 +01:00
|
|
|
|
EnterCriticalSection(&vga_lock);
|
2002-04-08 22:11:28 +02:00
|
|
|
|
|
2003-02-11 23:19:27 +01:00
|
|
|
|
if (lpddraw)
|
2002-04-08 22:11:28 +02:00
|
|
|
|
VGA_Poll_Graphics();
|
2003-02-11 23:19:27 +01:00
|
|
|
|
else
|
2002-04-08 22:11:28 +02:00
|
|
|
|
VGA_Poll_Text();
|
|
|
|
|
|
2003-01-28 01:16:15 +01:00
|
|
|
|
/*
|
|
|
|
|
* Fake start of retrace.
|
|
|
|
|
*/
|
|
|
|
|
vga_retrace_vertical = TRUE;
|
2003-02-11 23:19:27 +01:00
|
|
|
|
|
2002-04-08 22:11:28 +02:00
|
|
|
|
LeaveCriticalSection(&vga_lock);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static BYTE palreg,palcnt;
|
|
|
|
|
static PALETTEENTRY paldat;
|
|
|
|
|
|
|
|
|
|
void VGA_ioport_out( WORD port, BYTE val )
|
|
|
|
|
{
|
|
|
|
|
switch (port) {
|
2002-07-28 19:42:30 +02:00
|
|
|
|
case 0x3c0:
|
|
|
|
|
if (vga_address_3c0)
|
|
|
|
|
vga_index_3c0 = val;
|
|
|
|
|
else
|
2002-07-30 01:51:57 +02:00
|
|
|
|
FIXME("Unsupported index, register 0x3c0: 0x%02x (value 0x%02x)\n",
|
|
|
|
|
vga_index_3c0, val);
|
2002-07-28 19:42:30 +02:00
|
|
|
|
vga_address_3c0 = !vga_address_3c0;
|
|
|
|
|
break;
|
|
|
|
|
case 0x3c4:
|
|
|
|
|
vga_index_3c4 = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x3c5:
|
2002-08-13 05:17:42 +02:00
|
|
|
|
switch(vga_index_3c4) {
|
|
|
|
|
case 0x04: /* Sequencer: Memory Mode Register */
|
|
|
|
|
if(vga_fb_depth == 8)
|
|
|
|
|
VGA_SetWindowStart((val & 8) ? 0 : -1);
|
|
|
|
|
else
|
|
|
|
|
FIXME("Memory Mode Register not supported in this mode.\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
FIXME("Unsupported index, register 0x3c4: 0x%02x (value 0x%02x)\n",
|
|
|
|
|
vga_index_3c4, val);
|
|
|
|
|
}
|
|
|
|
|
break;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
case 0x3c8:
|
|
|
|
|
palreg=val; palcnt=0; break;
|
|
|
|
|
case 0x3c9:
|
|
|
|
|
((BYTE*)&paldat)[palcnt++]=val << 2;
|
|
|
|
|
if (palcnt==3) {
|
1999-03-14 13:23:17 +01:00
|
|
|
|
VGA_SetPalette(&paldat,palreg++,1);
|
|
|
|
|
palcnt=0;
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
1998-11-08 16:06:31 +01:00
|
|
|
|
break;
|
2002-07-30 01:51:57 +02:00
|
|
|
|
case 0x3ce:
|
|
|
|
|
vga_index_3ce = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x3cf:
|
2002-07-28 19:42:30 +02:00
|
|
|
|
FIXME("Unsupported index, register 0x3ce: 0x%02x (value 0x%02x)\n",
|
|
|
|
|
vga_index_3ce, val);
|
|
|
|
|
break;
|
|
|
|
|
case 0x3d4:
|
|
|
|
|
vga_index_3d4 = val;
|
|
|
|
|
break;
|
|
|
|
|
case 0x3d5:
|
|
|
|
|
FIXME("Unsupported index, register 0x3d4: 0x%02x (value 0x%02x)\n",
|
|
|
|
|
vga_index_3d4, val);
|
|
|
|
|
break;
|
2002-06-25 00:57:28 +02:00
|
|
|
|
default:
|
|
|
|
|
FIXME("Unsupported VGA register: 0x%04x (value 0x%02x)\n", port, val);
|
1998-11-01 13:51:47 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-11-08 16:06:31 +01:00
|
|
|
|
|
|
|
|
|
BYTE VGA_ioport_in( WORD port )
|
|
|
|
|
{
|
|
|
|
|
BYTE ret;
|
|
|
|
|
|
|
|
|
|
switch (port) {
|
2002-07-28 19:42:30 +02:00
|
|
|
|
case 0x3c1:
|
2002-07-30 01:51:57 +02:00
|
|
|
|
FIXME("Unsupported index, register 0x3c0: 0x%02x\n",
|
|
|
|
|
vga_index_3c0);
|
|
|
|
|
return 0xff;
|
|
|
|
|
case 0x3c5:
|
2002-08-13 05:17:42 +02:00
|
|
|
|
switch(vga_index_3c4) {
|
|
|
|
|
case 0x04: /* Sequencer: Memory Mode Register */
|
|
|
|
|
return (VGA_GetWindowStart() == -1) ? 0xf7 : 0xff;
|
|
|
|
|
default:
|
|
|
|
|
FIXME("Unsupported index, register 0x3c4: 0x%02x\n",
|
|
|
|
|
vga_index_3c4);
|
|
|
|
|
return 0xff;
|
|
|
|
|
}
|
2002-07-28 19:42:30 +02:00
|
|
|
|
case 0x3cf:
|
2002-07-30 01:51:57 +02:00
|
|
|
|
FIXME("Unsupported index, register 0x3ce: 0x%02x\n",
|
|
|
|
|
vga_index_3ce);
|
2002-07-28 19:42:30 +02:00
|
|
|
|
return 0xff;
|
2002-07-30 01:51:57 +02:00
|
|
|
|
case 0x3d5:
|
|
|
|
|
FIXME("Unsupported index, register 0x3d4: 0x%02x\n",
|
|
|
|
|
vga_index_3d4);
|
2002-07-28 19:42:30 +02:00
|
|
|
|
return 0xff;
|
2003-01-28 01:16:15 +01:00
|
|
|
|
|
1998-11-08 16:06:31 +01:00
|
|
|
|
case 0x3da:
|
2003-01-28 01:16:15 +01:00
|
|
|
|
/*
|
|
|
|
|
* Read from this register resets register 0x3c0 address flip-flop.
|
|
|
|
|
*/
|
|
|
|
|
vga_address_3c0 = TRUE;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Read from this register returns following bits:
|
|
|
|
|
* xxxx1xxx = Vertical retrace in progress if set.
|
|
|
|
|
* xxxxx1xx = Light pen switched on.
|
|
|
|
|
* xxxxxx1x = Light pen trigger set.
|
|
|
|
|
* xxxxxxx1 = Either vertical or horizontal retrace
|
|
|
|
|
* in progress if set.
|
|
|
|
|
*/
|
|
|
|
|
ret = 0;
|
|
|
|
|
if (vga_retrace_vertical)
|
|
|
|
|
ret |= 9;
|
|
|
|
|
if (vga_retrace_horizontal)
|
|
|
|
|
ret |= 3;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If VGA mode has been set, vertical retrace is
|
|
|
|
|
* turned on once a frame and cleared after each read.
|
|
|
|
|
* This might cause applications that synchronize with
|
|
|
|
|
* vertical retrace to actually skip one frame but that
|
|
|
|
|
* is probably not a problem.
|
|
|
|
|
*
|
|
|
|
|
* If no VGA mode has been set, vertical retrace is faked
|
|
|
|
|
* by toggling the value after every read.
|
|
|
|
|
*/
|
2002-11-24 23:15:56 +01:00
|
|
|
|
if (VGA_IsTimerRunning())
|
2003-01-28 01:16:15 +01:00
|
|
|
|
vga_retrace_vertical = FALSE;
|
2002-04-19 02:05:38 +02:00
|
|
|
|
else
|
2003-01-28 01:16:15 +01:00
|
|
|
|
vga_retrace_vertical = !vga_retrace_vertical;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Toggle horizontal retrace.
|
|
|
|
|
*/
|
|
|
|
|
vga_retrace_horizontal = !vga_retrace_horizontal;
|
1998-11-08 16:06:31 +01:00
|
|
|
|
break;
|
2003-01-28 01:16:15 +01:00
|
|
|
|
|
1998-11-08 16:06:31 +01:00
|
|
|
|
default:
|
|
|
|
|
ret=0xff;
|
2002-06-25 00:57:28 +02:00
|
|
|
|
FIXME("Unsupported VGA register: 0x%04x\n", port);
|
1998-11-08 16:06:31 +01:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2000-02-03 01:46:29 +01:00
|
|
|
|
|
|
|
|
|
void VGA_Clean(void)
|
|
|
|
|
{
|
|
|
|
|
VGA_Exit();
|
|
|
|
|
VGA_DeinstallTimer();
|
|
|
|
|
}
|