From 82b10945a53ca3f2623347f049bf73c082a75882 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 1 Mar 2008 21:30:46 +0200 Subject: [PATCH] imported winuaesrc1500b5.zip --- debug.c | 20 +- expansion.c | 19 +- hardfile.c | 6 +- include/blkdev.h | 1 + include/options.h | 2 +- jit/compemu_fpp.c | 2 + memory.c | 2 +- newcpu.c | 2 +- od-win32/blkdev_win32_aspi.c | 26 +- od-win32/blkdev_win32_spti.c | 67 +- od-win32/debug_win32.c | 666 +++++++++-- od-win32/dxwarp_old.c | 1950 ++++++++++++++++++++++++++++++ od-win32/dxwrap.c | 2095 ++++++--------------------------- od-win32/dxwrap.h | 202 +--- od-win32/dxwrap_old.h | 258 ++++ od-win32/mman.c | 41 +- od-win32/picasso96_win.c | 879 ++------------ od-win32/picasso96_win.h | 14 - od-win32/resources/resource.h | 7 +- od-win32/resources/winuae.rc | 56 +- od-win32/win32.c | 17 +- od-win32/win32.h | 4 +- od-win32/win32_scale2x.c | 35 +- od-win32/win32gfx.c | 1052 +++++------------ od-win32/win32gfx.h | 41 +- od-win32/win32gui.c | 696 +++++++---- od-win32/winuaechangelog.txt | 30 + scsiemul.c | 15 + table68k | 2 +- 29 files changed, 4279 insertions(+), 3928 deletions(-) create mode 100755 od-win32/dxwarp_old.c create mode 100755 od-win32/dxwrap_old.h diff --git a/debug.c b/debug.c index 9470a1ab..361ab4ea 100755 --- a/debug.c +++ b/debug.c @@ -137,6 +137,8 @@ static char help[] = { #ifdef _WIN32 " x Close debugger.\n" " xx Switch between console and GUI debugger.\n" + " mg
Memory dump starting at
in GUI\n" + " dg
Disassembly starting at
in GUI\n" #endif " q Quit the emulator. You don't want to use this command.\n\n" }; @@ -2543,7 +2545,7 @@ static void debug_1 (void) if (!debugger_active) return; - update_debug_info(); + update_debug_info (); console_out (">"); console_flush (); debug_linecounter = 0; @@ -2618,6 +2620,13 @@ static void debug_1 (void) } else if (*inptr == 't') { next_char (&inptr); debugtest_set (&inptr); +#ifdef _WIN32 + } else if (*inptr == 'g') { + extern void update_disassembly (uae_u32); + next_char (&inptr); + if (more_params (&inptr)) + update_disassembly (readhex (&inptr)); +#endif } else { uae_u32 daddr; int count; @@ -2730,6 +2739,15 @@ static void debug_1 (void) { uae_u32 maddr; int lines; +#ifdef _WIN32 + if (*inptr == 'g') { + extern void update_memdump (uae_u32); + next_char (&inptr); + if (more_params (&inptr)) + update_memdump (readhex (&inptr)); + break; + } +#endif if (more_params(&inptr)) { maddr = readhex(&inptr); } else { diff --git a/expansion.c b/expansion.c index ac01d254..8b29d54e 100755 --- a/expansion.c +++ b/expansion.c @@ -942,15 +942,11 @@ static void expamem_init_z3fastmem (void) */ uaecptr p96ram_start; -int p96mode = 1; static void expamem_map_gfxcard (void) { gfxmem_start = (expamem_hi | (expamem_lo >> 4)) << 16; - if (p96mode) - map_banks (&gfxmem_bankx, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem); - else - map_banks (&gfxmem_bank, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem); + map_banks (&gfxmem_bankx, gfxmem_start >> 16, allocated_gfxmem >> 16, allocated_gfxmem); write_log ("UAEGFX-card: mapped @$%lx, %d MB RTG RAM\n", gfxmem_start, allocated_gfxmem / 0x100000); } @@ -1065,7 +1061,6 @@ static void allocate_expamem (void) z3fastmem_bank.baseaddr = z3fastmem; fastmem_bank.baseaddr = fastmemory; - gfxmem_bank.baseaddr = NULL; gfxmem_bankx.baseaddr = gfxmemory; #ifdef SAVESTATE @@ -1083,12 +1078,8 @@ static void allocate_expamem (void) #ifdef PICASSO96 if (allocated_gfxmem > 0 && gfxmem_start > 0) { restore_ram (p96_filepos, gfxmemory); - if (p96mode) - map_banks (&gfxmem_bankx, gfxmem_start >> 16, currprefs.gfxmem_size >> 16, - allocated_gfxmem); - else - map_banks (&gfxmem_bank, gfxmem_start >> 16, currprefs.gfxmem_size >> 16, - allocated_gfxmem); + map_banks (&gfxmem_bankx, gfxmem_start >> 16, currprefs.gfxmem_size >> 16, + allocated_gfxmem); } #endif } @@ -1264,10 +1255,6 @@ void expamem_reset (void) } z3fastmem_start = currprefs.z3fastmem_start; - if (!canbang) - p96mode = 0; - if (!p96mode) - p96memstart(); (*card_init[0]) (); } diff --git a/hardfile.c b/hardfile.c index 86421a27..f5f13623 100755 --- a/hardfile.c +++ b/hardfile.c @@ -1009,9 +1009,13 @@ static uae_u32 hardfile_do_io (struct hardfiledata *hfd, struct hardfileprivdata case CMD_GETGEOMETRY: { int cyl, cylsec, head, tracksec; + uae_u64 size; getchs (hfd, &cyl, &cylsec, &head, &tracksec); put_long (dataptr + 0, hfd->blocksize); - put_long (dataptr + 4, (uae_u32)(hfd->size / hfd->blocksize)); + size = hfd->size / hfd->blocksize; + if (size > 0x00ffffffff) + size = 0xffffffff; + put_long (dataptr + 4, (uae_u32)size); put_long (dataptr + 8, cyl); put_long (dataptr + 12, cylsec); put_long (dataptr + 16, head); diff --git a/include/blkdev.h b/include/blkdev.h index 8498c6d4..57d5712c 100755 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -32,6 +32,7 @@ struct device_info { int type; int media_inserted; + int removable; int write_protected; int cylinders; int trackspercylinder; diff --git a/include/options.h b/include/options.h index 1c953048..cb2eea51 100755 --- a/include/options.h +++ b/include/options.h @@ -307,7 +307,7 @@ struct uae_prefs { int win32_iconified_pause; int win32_iconified_nosound; - int win32_no_overlay; /* If this is set, we won't try and use any RGB overlays */ + int win32_rtgmatchdepth; int win32_borderless; int win32_ctrl_F11_is_quit; int win32_automount_removable; diff --git a/jit/compemu_fpp.c b/jit/compemu_fpp.c index 4ee660d5..20afbed7 100755 --- a/jit/compemu_fpp.c +++ b/jit/compemu_fpp.c @@ -511,6 +511,7 @@ void comp_fscc_opp (uae_u32 opcode, uae_u16 extra) if (!(opcode & 0x38)) mov_b_rr(reg,S4); +#if 0 else { abort(); if (!comp_fp_adr (opcode)) { @@ -520,6 +521,7 @@ void comp_fscc_opp (uae_u32 opcode, uae_u16 extra) else put_byte (ad, cc ? 0xff : 0x00); } +#endif } void comp_ftrapcc_opp (uae_u32 opcode, uaecptr oldpc) diff --git a/memory.c b/memory.c index a2db0946..f2b639cf 100755 --- a/memory.c +++ b/memory.c @@ -39,7 +39,7 @@ int special_mem; static int canjit (void) { - if (canbang) + if (canbang || currprefs.cpu_model >= 68020) return 1; return 0; } diff --git a/newcpu.c b/newcpu.c index 8d8ba73a..067a47f2 100755 --- a/newcpu.c +++ b/newcpu.c @@ -7,7 +7,7 @@ */ #define MOVEC_DEBUG 0 -#define MMUOP_DEBUG 1 +#define MMUOP_DEBUG 2 #include "sysconfig.h" #include "sysdeps.h" diff --git a/od-win32/blkdev_win32_aspi.c b/od-win32/blkdev_win32_aspi.c index 5e1f3be9..38baac99 100755 --- a/od-win32/blkdev_win32_aspi.c +++ b/od-win32/blkdev_win32_aspi.c @@ -42,6 +42,7 @@ struct scsi_info { char label[100]; SCSI *handle; int isatapi; + int removable; }; static struct scsi_info si[MAX_TOTAL_DEVICES]; static int unitcnt; @@ -707,6 +708,7 @@ static void scan_scsi_bus (SCSI *scgp, int flags) cis->target = scgp->addr.target; cis->lun = scgp->addr.lun; cis->type = inq.type; + cis->removable = inq.removable; sprintf (cis->label, "%.8s %.16s %.4s", inq.vendor_info, inq.prod_ident, inq.prod_revision); } } @@ -812,21 +814,25 @@ static int mediacheck_full (int unitnum, struct device_info *di) int ok, outlen; uae_u8 *p = si[unitnum].buf; - di->bytespersector = 2048; - di->cylinders = 1; + di->sectorspertrack = 0; + di->trackspercylinder = 0; + di->bytespersector = 0; + di->cylinders = 0; di->write_protected = 1; if (si[unitnum].handle == 0) return 0; ok = execscsicmd_in(unitnum, cmd1, sizeof cmd1, &outlen) ? 1 : 0; if (ok) { di->bytespersector = (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]; - di->cylinders = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + di->sectorspertrack = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + di->trackspercylinder = 1; + di->cylinders = 1; } if (di->type == INQ_DASD) { uae_u8 cmd2[10] = { 0x5a,0x08,0,0,0,0,0,0,0x10,0 }; /* MODE SENSE */ ok = execscsicmd_in(unitnum, cmd2, sizeof cmd2, &outlen) ? 1 : 0; if (ok) { - di->write_protected = (p[3]& 0x80) ? 1 : 0; + di->write_protected = (p[3] & 0x80) ? 1 : 0; } } return 1; @@ -932,16 +938,18 @@ static int execscsicmd_direct (int unitnum, struct amigascsi *as) static struct device_info *info_device (int unitnum, struct device_info *di) { + struct scsi_info *sif = &si[unitnum]; if (unitnum >= unitcnt) return 0; - di->bus = si[unitnum].scsibus; - di->target = si[unitnum].target; - di->lun = si[unitnum].lun; + di->bus = sif->scsibus; + di->target = sif->target; + di->lun = sif->lun; di->media_inserted = mediacheck (unitnum); - di->type = si[unitnum].type; + di->type = sif->type; mediacheck_full (unitnum, di); di->id = unitnum + 1; - di->label = my_strdup (si[unitnum].label); + di->removable = sif->removable; + di->label = my_strdup (sif->label); if (log_scsi) { write_log ("MI=%d TP=%d WP=%d CY=%d BK=%d '%s'\n", di->media_inserted, di->type, di->write_protected, di->cylinders, di->bytespersector, di->label); diff --git a/od-win32/blkdev_win32_spti.c b/od-win32/blkdev_win32_spti.c index 2add73b5..82f4c214 100755 --- a/od-win32/blkdev_win32_spti.c +++ b/od-win32/blkdev_win32_spti.c @@ -51,6 +51,7 @@ struct dev_info_spti { int mediainserted; HANDLE handle; int isatapi; + int removable; int type; int bus, path, target, lun; int scanmode; @@ -271,33 +272,36 @@ static void close_scsi_bus (void) free_scsi_device(i); } -static int inquiry (int unitnum, int *type, uae_u8 *inquirydata, int *inqlen) +static int inquiry (int unitnum, struct dev_info_spti *di, uae_u8 *inquirydata) { uae_u8 cmd[6] = { 0x12,0,0,0,36,0 }; /* INQUIRY */ uae_u8 out[INQUIRY_SIZE] = { 0 }; int outlen = sizeof (out); uae_u8 *p = execscsicmd_in (unitnum, cmd, sizeof (cmd), &outlen); - int v = 0; + int inqlen = 0; - *inqlen = 0; - *type = 0x1f; + di->isatapi = 0; + di->removable = 0; + di->type = 0x1f; if (!p) { if (log_scsi) write_log ("SPTI: INQUIRY failed\n"); return 0; } - *inqlen = outlen > INQUIRY_SIZE ? INQUIRY_SIZE : outlen; - if (outlen >= 1) - *type = p[0] & 31; + inqlen = outlen > INQUIRY_SIZE ? INQUIRY_SIZE : outlen; + if (outlen >= 1) { + di->type = p[0] & 31; + di->removable = (p[1] & 0x80) ? 1 : 0; + } if (outlen >= 2 && (p[0] & 31) == 5 && (p[2] & 7) == 0) - v = 1; - memcpy (inquirydata, p, *inqlen); + di->isatapi = 1; + memcpy (inquirydata, p, inqlen); if (log_scsi) { if (outlen >= INQUIRY_SIZE) write_log ("SPTI: INQUIRY: %02.2X%02.2X%02.2X %d '%-8.8s' '%-16.16s'\n", - p[0], p[1], p[2], v, p + 8, p + 16); + p[0], p[1], p[2], di->isatapi, p + 8, p + 16); } - return v; + return inqlen; } static int mediacheck (int unitnum) @@ -316,8 +320,10 @@ static int mediacheck_full (int unitnum, struct device_info *di) uae_u8 *p; int outlen; - di->bytespersector = 2048; - di->cylinders = 1; + di->sectorspertrack = 0; + di->trackspercylinder = 0; + di->bytespersector = 0; + di->cylinders = 0; di->write_protected = 1; if (dev_info[unitnum].handle == INVALID_HANDLE_VALUE) return 0; @@ -325,14 +331,16 @@ static int mediacheck_full (int unitnum, struct device_info *di) p = execscsicmd_in(unitnum, cmd1, sizeof cmd1, &outlen); if (p && outlen >= 8) { di->bytespersector = (p[4] << 24) | (p[5] << 16) | (p[6] << 8) | p[7]; - di->cylinders = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + di->sectorspertrack = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + di->trackspercylinder = 1; + di->cylinders = 1; } if (di->type == INQ_DASD) { uae_u8 cmd2[10] = { 0x5a,0x08,0,0,0,0,0,0,0xf0,0 }; /* MODE SENSE */ outlen = 32; p = execscsicmd_in(unitnum, cmd2, sizeof cmd2, &outlen); if (p && outlen >= 4) { - di->write_protected = (p[3]& 0x80) ? 1 : 0; + di->write_protected = (p[3] & 0x80) ? 1 : 0; } } return 1; @@ -363,9 +371,7 @@ int open_scsi_device (int unitnum) write_log ("SPTI: failed to open unit %d err=%d ('%s')\n", unitnum, GetLastError(), dev); } else { uae_u8 inqdata[INQUIRY_SIZE + 1] = { 0 }; - int inqlen; - dev_info[unitnum].isatapi = inquiry (unitnum, &dev_info[unitnum].type, inqdata, &inqlen); - if (inqlen == 0) { + if (!inquiry (unitnum, di, inqdata)) { write_log ("SPTI: inquiry failed unit %d ('%s':%d:%d:%d:%d)\n", unitnum, dev, di->bus, di->path, di->target, di->lun); close_scsi_device (unitnum); @@ -373,18 +379,18 @@ int open_scsi_device (int unitnum) return 0; } inqdata[INQUIRY_SIZE] = 0; - if (dev_info[unitnum].type == INQ_ROMD) { + if (di->type == INQ_ROMD) { dev_info[unitnum].mediainserted = mediacheck (unitnum); write_log ("SPTI: unit %d opened [%s], %s, '%s'\n", unitnum, - dev_info[unitnum].isatapi ? "ATAPI" : "SCSI", - dev_info[unitnum].mediainserted ? "media inserted" : "drive empty", inqdata + 8); + di->isatapi ? "ATAPI" : "SCSI", + di->mediainserted ? "media inserted" : "drive empty", inqdata + 8); } else { write_log ("SPTI: unit %d, type %d, '%s'\n", - unitnum, dev_info[unitnum].type, inqdata + 8); + unitnum, di->type, inqdata + 8); } - dev_info[unitnum].name = my_strdup (inqdata + 8); - dev_info[unitnum].inquirydata = xmalloc (INQUIRY_SIZE); - memcpy (dev_info[unitnum].inquirydata, inqdata, INQUIRY_SIZE); + di->name = my_strdup (inqdata + 8); + di->inquirydata = xmalloc (INQUIRY_SIZE); + memcpy (di->inquirydata, inqdata, INQUIRY_SIZE); xfree (dev); return 1; } @@ -436,19 +442,22 @@ static int adddrive (char *drvpath, int bus, int pathid, int targetid, int lunid static struct device_info *info_device (int unitnum, struct device_info *di) { + struct dev_info_spti *dispti; if (unitnum >= MAX_TOTAL_DEVICES || dev_info[unitnum].handle == INVALID_HANDLE_VALUE) return 0; - di->label = my_strdup(dev_info[unitnum].name); + dispti = &dev_info[unitnum]; + di->label = my_strdup(dispti->name); di->bus = 0; di->target = unitnum; di->lun = 0; di->media_inserted = mediacheck (unitnum); + di->removable = dispti->removable; mediacheck_full (unitnum, di); - di->type = dev_info[unitnum].type; + di->type = dispti->type; di->id = unitnum + 1; if (log_scsi) { - write_log ("MI=%d TP=%d WP=%d CY=%d BK=%d '%s'\n", - di->media_inserted, di->type, di->write_protected, di->cylinders, di->bytespersector, di->label); + write_log ("MI=%d TP=%d WP=%d CY=%d BK=%d RMB=%d '%s'\n", + di->media_inserted, di->type, di->write_protected, di->cylinders, di->bytespersector, di->removable, di->label); } return di; } diff --git a/od-win32/debug_win32.c b/od-win32/debug_win32.c index b783179e..0378e47c 100755 --- a/od-win32/debug_win32.c +++ b/od-win32/debug_win32.c @@ -1,7 +1,7 @@ /* * WinUAE GUI debugger * - * Copyright 2007 Karsten Bock + * Copyright 2008 Karsten Bock * Copyright 2007 Toni Wilen * */ @@ -10,7 +10,9 @@ #include "sysdeps.h" #include +#include #include +#include #include #include "resource.h" #include "options.h" @@ -33,10 +35,13 @@ static HWND hDbgWnd = 0; static HWND hOutput = 0; static HACCEL dbgaccel = 0; static HFONT udfont = 0; +static HWND hedit = 0; extern int consoleopen; BOOL debuggerinitializing = FALSE; + extern uae_u32 get_fpsr(); +extern void set_fpsr(uae_u32 x); static char linebreak[] = {'\r', '\n', '\0'}; @@ -63,12 +68,11 @@ static int histcount; struct debuggerpage { HWND ctrl[MAXPAGECONTROLS]; uae_u32 memaddr; - int memsel; uae_u32 dasmaddr; - int dasmsel; char addrinput[9]; + int selection; int init; - BOOL autoset; + int autoset; }; static struct debuggerpage dbgpage[MAXPAGES]; static int currpage, pages; @@ -82,6 +86,7 @@ static int dbgwnd_minx = 800, dbgwnd_miny = 600; static BOOL useinternalcmd = FALSE; static char internalcmd[MAX_LINEWIDTH + 1]; +static const char *markinstr[] = { "JMP", "BT ", "RTS", "RTD", "RTE", "RTR", 0 }; static const char *ucbranch[] = { "BSR", "JMP", "JSR", 0 }; static const char *cbranch[] = { "B", "DB", "FB", "FDB", 0 }; static const char *ccode[] = { "T ", "F ", "HI", "LS", "CC", "CS", "NE", "EQ", @@ -595,7 +600,7 @@ static void ShowDasm(int direction) addr = m68k_getpc (®s); dbgpage[currpage].init = 1; } - else if (dbgpage[currpage].autoset && direction == 0) { + else if (dbgpage[currpage].autoset == 1 && direction == 0) { addr = m68k_getpc (®s); } else @@ -709,9 +714,9 @@ static void AddPage(int *iddata) ShowWindow(dbgpage[pages].ctrl[i], SW_HIDE); } if (pages == 0) - dbgpage[pages].autoset = TRUE; + dbgpage[pages].autoset = 1; else - dbgpage[pages].autoset = FALSE; + dbgpage[pages].autoset = 0; pages++; } @@ -772,17 +777,23 @@ static LRESULT CALLBACK InputProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM WNDPROC oldproc; switch (message) { + case WM_CHAR: + if (!debugger_active) + return 0; + break; case WM_KEYUP: + if (!debugger_active) + return 0; switch (wParam) { case VK_RETURN: inputfinished = 1; break; case VK_UP: SetPrevHistNode(hWnd); - return TRUE; + return 0; case VK_DOWN: SetNextHistNode(hWnd); - return TRUE; + return 0; } break; } @@ -790,8 +801,6 @@ static LRESULT CALLBACK InputProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM return CallWindowProc(oldproc, hWnd, message, wParam, lParam); } -static int addrinputdialogactive; - static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HANDLE hdata; @@ -804,10 +813,17 @@ static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LP switch (message) { case WM_CHAR: - if (wParam == VK_BACK) - break; - if (!strchr(allowed, wParam)) - return TRUE; + switch (wParam) { + case VK_BACK: + case VK_CANCEL: //ctrl+c + case VK_FINAL: //ctrl+x + case 0x16: //ctrl+v + break; + default: + if (!debugger_active || !strchr(allowed, wParam)) + return 0; + break; + } break; case WM_PASTE: if (!OpenClipboard(NULL)) @@ -823,9 +839,11 @@ static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LP } CloseClipboard(); if (!ok) - return TRUE; + return 0; break; case WM_KEYUP: + if (!debugger_active) + return 0; switch (wParam) { case VK_RETURN: sprintf(addrstr, "0x"); @@ -837,12 +855,13 @@ static LRESULT CALLBACK MemInputProc (HWND hWnd, UINT message, WPARAM wParam, LP ShowMem(0); } else if (pagetype == IDC_DBG_DASM) { + if (dbgpage[currpage].autoset) + dbgpage[currpage].autoset = 2; dbgpage[currpage].dasmaddr = addr; ShowDasm(0); } } - addrinputdialogactive = -1; - break; + return 0; } break; } @@ -858,72 +877,57 @@ static INT_PTR CALLBACK AddrInputDialogProc(HWND hDlg, UINT msg, WPARAM wParam, PostQuitMessage (0); return TRUE; case WM_CLOSE: - addrinputdialogactive = 0; - DestroyWindow(hDlg); + EndDialog(hDlg, 0); return TRUE; case WM_INITDIALOG: { + RECT r; WNDPROC oldproc; + DWORD msgpos = GetMessagePos(); HWND hwnd = GetDlgItem(hDlg, IDC_DBG_MEMINPUT2); SendMessage(hwnd, EM_LIMITTEXT, 8, 0); oldproc = (WNDPROC)SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)MemInputProc); SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG_PTR)oldproc); + GetWindowRect(hDlg, &r); + r.right -= r.left; + r.bottom -= r.top; + r.left = GET_X_LPARAM(msgpos) - r.right / 2; + r.top = GET_Y_LPARAM(msgpos) - r.bottom / 2; + MoveWindow(hDlg, r.left, r.top, r.right, r.bottom, FALSE); + ShowWindow(hDlg, SW_SHOWNORMAL); + SetFocus(GetDlgItem(hDlg, IDC_DBG_MEMINPUT2)); return TRUE; } case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDOK: - addrinputdialogactive = -1; - DestroyWindow (hDlg); - return TRUE; - case IDCANCEL: - addrinputdialogactive = 0; - DestroyWindow (hDlg); - return TRUE; + switch (LOWORD(wParam)) { + case IDOK: + { + char addrstr[11] = { '0', 'x', '\0' }; + + SendMessage(GetDlgItem(hDlg, IDC_DBG_MEMINPUT2), WM_GETTEXT, 9, (LPARAM)addrstr + 2); + if (addrstr[2] != 0) { + uae_u32 addr = strtoul(addrstr, NULL, 0); + if (dbgpage[currpage].selection == IDC_DBG_MEM || dbgpage[currpage].selection == IDC_DBG_MEM2) { + dbgpage[currpage].memaddr = addr; + ShowMem(0); + } + else { + if (dbgpage[currpage].autoset) + dbgpage[currpage].autoset = 2; + dbgpage[currpage].dasmaddr = addr; + ShowDasm(0); + } + } + EndDialog(hDlg, 1); + return TRUE; + } + case IDCANCEL: + EndDialog(hDlg, 0); + return TRUE; } - break; - } - return FALSE; -} - -static void ShowAddrInputDialog(HWND hparent) -{ - HWND hwnd; - char addrstr[11]; - uae_u32 addr; - - addrinputdialogactive = 1; - sprintf(addrstr, "0x"); - hwnd = CustomCreateDialog (IDD_DBGMEMINPUT, hparent, (DLGPROC)AddrInputDialogProc); - if (hwnd == NULL) - return; - SetFocus(GetDlgItem(hwnd, IDC_DBG_MEMINPUT2)); - while (addrinputdialogactive == 1) { - MSG msg; - int ret; - WaitMessage(); - while ((ret = GetMessage (&msg, NULL, 0, 0))) { - if (ret == -1) break; - if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) { - TranslateMessage (&msg); - DispatchMessage (&msg); - } - SendMessage(GetDlgItem(hwnd, IDC_DBG_MEMINPUT2), WM_GETTEXT, 9, (LPARAM)addrstr + 2); - } - if (addrinputdialogactive == -1) { - if (addrstr[2] != 0) { - addr = strtoul(addrstr, NULL, 0); - dbgpage[currpage].memaddr = addr; - ShowMem(0); - } - SetFocus(hDbgWnd); - return; - } } - return; - + return FALSE; } static void CopyListboxText(HWND hwnd, BOOL all) @@ -943,10 +947,7 @@ static void CopyListboxText(HWND hwnd, BOOL all) } else { int id = GetDlgCtrlID(hwnd); - if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) - start = dbgpage[currpage].memsel; - else - start = dbgpage[currpage].dasmsel; + start = dbgpage[currpage].selection; end = start + 1; } for (i = start; i < end; i++) @@ -973,7 +974,7 @@ static void CopyListboxText(HWND hwnd, BOOL all) static void ToggleBreakpoint(HWND hwnd) { char addrstr[MAX_LINEWIDTH + 1], *ptr; - int index = dbgpage[currpage].dasmsel; + int index = dbgpage[currpage].selection; SendMessage(hwnd, LB_GETTEXT, index, (LPARAM)addrstr); addrstr[8] = '\0'; ptr = addrstr; @@ -990,6 +991,343 @@ static void DeleteBreakpoints(HWND hwnd) RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE); } +static void ignore_ws (char **c) +{ + while (**c && isspace(**c)) + (*c)++; +} + +static void ListboxEndEdit(HWND hwnd, BOOL acceptinput) +{ + MSG msg; + char *p, *p2, txt[MAX_LINEWIDTH + 1], tmp[MAX_LINEWIDTH + 1], hexstr[11] = { '0', 'x', '\0' }; + + if (!hedit) + return; + ReleaseCapture(); + memset(txt, 0, MAX_LINEWIDTH + 1); + GetWindowText(hedit, txt, MAX_LINEWIDTH + 1); + p = txt; + ignore_ws(&p); + if ((GetWindowTextLength(hedit) == 0) || (strlen(p) == 0)) + acceptinput = FALSE; + while (PeekMessage(&msg, hedit, 0, 0, PM_REMOVE)) + ; + DestroyWindow(hedit); + hedit = NULL; + if (acceptinput) { + int index = dbgpage[currpage].selection, id = GetDlgCtrlID(hwnd); + if (id == IDC_DBG_DREG) { + strncpy(hexstr + 2, txt, 8); + hexstr[10] = '\0'; + m68k_dreg(®s, index) = strtoul(hexstr, NULL, 0); + } + else if (id == IDC_DBG_AREG) { + strncpy(hexstr + 2, txt, 8); + hexstr[10] = '\0'; + m68k_areg(®s, index) = strtoul(hexstr, NULL, 0); + } + else if (id == IDC_DBG_FPREG) { + char *stopstr; + double value; + errno = 0; + value = strtod(txt, &stopstr); + if (strlen(stopstr) == 0 && errno == 0) + regs.fp[index] = strtod(txt, &stopstr); + } + else { + int bytes, i, offset = -1; + uae_u8 value; + uae_u32 addr; + SendMessage(hwnd, LB_GETTEXT, index, (LPARAM)tmp); + if (id == IDC_DBG_AMEM) { + addr = m68k_areg(®s, index); + offset = 0; + bytes = 16; + } + else if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) { + strncpy(hexstr + 2, tmp, 8); + hexstr[10] = '\0'; + addr = strtoul(hexstr, NULL, 0); + offset = 9; + bytes = 16; + } + else if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { + strncpy(hexstr + 2, tmp, 8); + hexstr[10] = '\0'; + addr = strtoul(hexstr, NULL, 0); + bytes = 0; + p = tmp + 9; + while (isxdigit(p[0]) && p[4] == ' ') { + bytes += 2; + p += 5; + } + } + if (offset >= 0 && !isxdigit(tmp[offset])) { + int t = 0; + do { + t += 5; + addr += 2; + bytes -= 2; + } while (!isxdigit(tmp[offset + t]) && !isxdigit(tmp[offset + t + 1]) && isspace(tmp[offset + t + 4])); + } + p = txt; + for (i = 0; i < bytes; i++) { + ignore_ws(&p); + if (!isxdigit(p[0])) + break; + p2 = p + 1; + ignore_ws(&p2); + if (!isxdigit(p2[0])) + break; + hexstr[2] = p[0]; + hexstr[3] = p2[0]; + hexstr[4] = '\0'; + value = (uae_u8)strtoul(hexstr, NULL, 0); + put_byte(addr, value); + p = p2 + 1; + addr++; + } + } + update_debug_info(); + } + else + RedrawWindow(hwnd, 0, 0, RDW_INVALIDATE); +} + +static LRESULT CALLBACK ListboxEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + HANDLE hdata; + LPTSTR lptstr; + char allowed[] = "1234567890abcdefABCDEF "; + int ok = 1, id; + WNDPROC oldproc; + HWND hparent = GetParent(hWnd); + id = GetDlgCtrlID(hparent); + if (id == IDC_DBG_DREG || id == IDC_DBG_AREG) + allowed[strlen(allowed) - 1] = '\0'; // no space + else if (id == IDC_DBG_FPREG) + sprintf(allowed, "1234567890deDE.+-"); + switch (message) { + case WM_GETDLGCODE: + return DLGC_WANTALLKEYS; + case WM_MOUSELEAVE: + { + HWND hwcapt = GetCapture(); + if (!hwcapt) + SetCapture(hWnd); + break; + } + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + { + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + RECT rc; + GetClientRect(hWnd, &rc); + if (!PtInRect(&rc, pt)) + ListboxEndEdit(hparent, TRUE); + break; + } + case WM_CHAR: + switch (wParam) { + case VK_BACK: + case VK_CANCEL: //ctrl+c + case VK_FINAL: //ctrl+x + case 0x16: //ctrl+v + break; + case VK_ESCAPE: + ListboxEndEdit(hparent, FALSE); + return 0; + default: + if (!strchr(allowed, wParam)) + return 0; + break; + } + break; + case WM_PASTE: + if (!OpenClipboard(NULL)) + return TRUE; + hdata = GetClipboardData(CF_TEXT); + if (hdata) { + lptstr = GlobalLock(hdata); + if (lptstr) { + if (strspn(lptstr, allowed) != strlen(lptstr)) + ok = 0; + GlobalUnlock(hdata); + } + } + CloseClipboard(); + if (!ok) + return 0; + break; + case WM_KEYUP: + if (wParam == VK_RETURN) + ListboxEndEdit(hparent, TRUE); + break; + } + oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); + return CallWindowProc(oldproc, hWnd, message, wParam, lParam); +} + +static void ListboxEdit(HWND hwnd, int x, int y) +{ + int size, id, offset, length, index, radjust = 0; + RECT rc, ri; + HFONT hfont; + WNDPROC oldproc; + char txt[MAX_LINEWIDTH + 1], tmp[MAX_LINEWIDTH + 1]; + if (!debugger_active || hedit) + return; + if (!hwnd) + hwnd = GetParent(hedit); + id = GetDlgCtrlID(hwnd); + if (id == IDC_DBG_DREG || id == IDC_DBG_AREG) { + offset = 4; + length = 0; + } + else if(id == IDC_DBG_MEM || id == IDC_DBG_MEM2) { + offset = 9; + length = 39; + } + else if (id == IDC_DBG_AMEM) { + offset = 0; + length = 39; + } + else if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { + offset = 9; + length = 0; + } + else if (id == IDC_DBG_FPREG) { + offset = 5; + length = 0; + } + else + return; + hedit = CreateWindow("Edit", "Listbox Edit", WS_BORDER | WS_CHILD, 0, 0, 1, 1, hwnd, NULL, hInst, NULL); + if (!hedit) + return; + size = GetTextSize(hwnd, NULL, 0); + index = y / size; + memset(txt, 0, MAX_LINEWIDTH + 1); + SendMessage(hwnd, LB_GETITEMRECT, (WPARAM)index, (LPARAM)&ri); + SendMessage(hwnd, LB_GETTEXT, (WPARAM)index, (LPARAM)(LPTSTR)txt); + if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { + while (isxdigit(txt[offset + length]) && isspace(txt[offset + length + 4])) + length += 5; + length--; + } + if (length > 0) { + int t = 0; + if (!isxdigit(txt[offset])) { + while (isxdigit(txt[offset + length - t - 1]) && isspace(txt[offset + length - t - 5])) + t += 5; + offset += length - t + 1; + length = t - 1; + } + else if (!isxdigit(txt[offset + length - 1])) { + while (isxdigit(txt[offset + t]) && isspace(txt[offset + t + 4])) + t += 5; + length = t - 1; + } + if (length <= 0) { + ListboxEndEdit(hwnd, FALSE); + return; + } + strncpy(tmp, txt + offset, length); + tmp[length] = '\0'; + radjust = GetTextSize(hwnd, tmp, TRUE); + } + else if (id == IDC_DBG_FPREG) + length = 20; + else + length = strlen(txt + offset); + strncpy(tmp, txt, offset); + tmp[offset] = '\0'; + ri.left += GetTextSize(hwnd, tmp, TRUE); + if (radjust) + ri.right = ri.left + radjust; + InflateRect(&ri, 2, 2); + GetClientRect(hwnd, &rc); + if (ri.left < 0) + OffsetRect(&ri, 2, 0); + else if (ri.right > rc.right) + OffsetRect(&ri, -2, 0); + if (index == 0) + OffsetRect(&ri, 0, 2); + else if (ri.bottom > rc.bottom) + OffsetRect(&ri, 0, -2); + if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) + OffsetRect(&ri, 2 * size, 0); + SendMessage(hedit, EM_LIMITTEXT, length, 0); + MoveWindow(hedit, ri.left, ri.top, ri.right - ri.left, ri.bottom - ri.top, FALSE); + ShowWindow(hedit, SW_SHOWNORMAL); + oldproc = (WNDPROC)SetWindowLongPtr(hedit, GWL_WNDPROC, (LONG_PTR)ListboxEditProc); + SetWindowLongPtr(hedit, GWL_USERDATA, (LONG_PTR)oldproc); + hfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); + SendMessage(hedit, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE); + memset(txt + offset + length, 0, MAX_LINEWIDTH + 1 - offset - length); + SetWindowText(hedit, txt + offset); + SetFocus(hedit); + SetCapture(hedit); + dbgpage[currpage].selection = index; +} + +static void ToggleCCRFlag(HWND hwnd, int x, int y) +{ + int size = GetTextSize(hwnd, NULL, 0); + int index = y / size; + char txt[MAX_LINEWIDTH + 1]; + + memset(txt, 0, MAX_LINEWIDTH + 1); + SendMessage(hwnd, LB_GETTEXT, (WPARAM)index, (LPARAM)(LPTSTR)txt); + switch (txt[0]) { + case 'X': + SET_XFLG(®s.ccrflags, GET_XFLG(®s.ccrflags) ? 0 : 1); + break; + case 'N': + SET_NFLG(®s.ccrflags, GET_NFLG(®s.ccrflags) ? 0 : 1); + break; + case 'Z': + SET_ZFLG(®s.ccrflags, GET_ZFLG(®s.ccrflags) ? 0 : 1); + break; + case 'V': + SET_VFLG(®s.ccrflags, GET_VFLG(®s.ccrflags) ? 0 : 1); + break; + case 'C': + SET_CFLG(®s.ccrflags, GET_CFLG(®s.ccrflags) ? 0 : 1); + break; + } + update_debug_info(); +} + +static void set_fpsr (uae_u32 x) +{ + uae_u32 dhex_nan[] ={0xffffffff, 0x7fffffff}; + double *fp_nan = (double *)dhex_nan; + regs.fpsr = x; + + if (x & 0x01000000) { + regs.fp_result = *fp_nan; + } + else if (x & 0x04000000) + regs.fp_result = 0; + else if (x & 0x08000000) + regs.fp_result = -1; + else + regs.fp_result = 1; +} + +static void ToggleFPSRFlag(HWND hwnd, int x, int y) +{ + int size = GetTextSize(hwnd, NULL, 0); + int index = y / size; + uae_u32 fpsr = get_fpsr(); + + fpsr ^= (0x8000000 >> index); + set_fpsr(fpsr); + update_debug_info(); +} + static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDPROC oldproc; @@ -1004,14 +1342,27 @@ static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPAR switch (message) { case WM_CHAR: - hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); - SetFocus(hinput); - SendMessage(hinput, WM_CHAR, wParam, lParam); - return TRUE; + if (debugger_active) { + hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); + SetFocus(hinput); + SendMessage(hinput, WM_CHAR, wParam, lParam); + } + return 0; case WM_ERASEBKGND: - return TRUE; + return 1; case WM_SETFOCUS: - return TRUE; + return 0; + case WM_LBUTTONDBLCLK: + if (debugger_active) { + int id = GetDlgCtrlID(hWnd); + if (id == IDC_DBG_CCR) + ToggleCCRFlag(hWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + else if (id == IDC_DBG_FPSR) + ToggleFPSRFlag(hWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + else + ListboxEdit(hWnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + } + return 0; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rc); @@ -1060,7 +1411,7 @@ static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPAR DeleteObject(compbmp); DeleteDC(compdc); EndPaint(hWnd, &ps); - return TRUE; + return 0; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_DBG_SETTOA0: @@ -1071,25 +1422,31 @@ static LRESULT CALLBACK ListboxProc(HWND hWnd, UINT message, WPARAM wParam, LPAR case ID_DBG_SETTOA5: case ID_DBG_SETTOA6: case ID_DBG_SETTOA7: - dbgpage[currpage].memaddr = m68k_areg(®s, LOWORD(wParam) - ID_DBG_SETTOA0); + dbgpage[currpage].memaddr = m68k_areg(®s, LOWORD(wParam) - ID_DBG_SETTOA0); ShowMem(0); - return TRUE; + return 0; + case ID_DBG_SETTOPC: + dbgpage[currpage].dasmaddr = m68k_getpc(®s); + ShowDasm(0); + return 0; case ID_DBG_ENTERADDR: - ShowAddrInputDialog(hWnd); - return TRUE; + dbgpage[currpage].selection = GetDlgCtrlID(hWnd); + CustomDialogBox(IDD_DBGMEMINPUT, hWnd, (DLGPROC)AddrInputDialogProc); + return 0; case ID_DBG_COPYLBLINE: CopyListboxText(hWnd, FALSE); - return TRUE; + return 0; case ID_DBG_COPYLB: CopyListboxText(hWnd, TRUE); - return TRUE; + return 0; case ID_DBG_TOGGLEBP: ToggleBreakpoint(hWnd); - return TRUE; + return 0; case ID_DBG_DELETEBPS: DeleteBreakpoints(hWnd); - return TRUE; + return 0; } + break; } oldproc = (WNDPROC)GetWindowLongPtr(hWnd, GWL_USERDATA); return CallWindowProc(oldproc, hWnd, message, wParam, lParam); @@ -1103,10 +1460,12 @@ static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM switch (message) { case WM_CHAR: if (wParam != VK_CANCEL) { // not for Ctrl-C for copying - hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); - SetFocus(hinput); - SendMessage(hinput, WM_CHAR, wParam, lParam); - return TRUE; + if (debugger_active) { + hinput = GetDlgItem(hDbgWnd, IDC_DBG_INPUT); + SetFocus(hinput); + SendMessage(hinput, WM_CHAR, wParam, lParam); + } + return 0; } break; } @@ -1219,12 +1578,14 @@ static BOOL CALLBACK childenumproc (HWND hwnd, LPARAM lParam) static void AdjustDialog(HWND hDlg) { RECT r, r2; + WINDOWINFO pwi = { sizeof(WINDOWINFO) }; GetClientRect(hDlg, &r); width_adjust = (r.right - r.left) - (dlgRect.right - dlgRect.left); height_adjust = (r.bottom - r.top) - (dlgRect.bottom - dlgRect.top); GetWindowRect(hDlg, &dlgRect); r2.left = r2.top = r2.right = r2.bottom = 0; - AdjustWindowRect(&r2, WS_POPUP | WS_CAPTION | WS_THICKFRAME, FALSE); + GetWindowInfo(hDlg, &pwi); + AdjustWindowRectEx(&r2, pwi.dwStyle, FALSE, pwi.dwExStyle); dlgRect.left -= r2.left; dlgRect.top -= r2.top; randidx = -1; @@ -1311,19 +1672,20 @@ static void ShowContextMenu(HWND hwnd, int x, int y) POINT pt = { x, y }; HMENU hmenu, hsubmenu; int id = GetDlgCtrlID(hwnd); - if (x == 65535 && y == 65535) { + if (x == -1 || y == -1) { DWORD msgpos = GetMessagePos(); - pt.x = LOWORD(msgpos); - pt.y = HIWORD(msgpos); + pt.x = GET_X_LPARAM(msgpos); + pt.y = GET_Y_LPARAM(msgpos); } hmenu = LoadMenu(hUIDLL ? hUIDLL : hInst, MAKEINTRESOURCE(IDM_DBGCONTEXTMENU)); if (!hmenu) return; - - if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) + if (!debugger_active) hsubmenu = GetSubMenu(hmenu, 0); - else if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) + else if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) hsubmenu = GetSubMenu(hmenu, 1); + else if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) + hsubmenu = GetSubMenu(hmenu, 2); TrackPopupMenu(hsubmenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL); DestroyMenu(hmenu); SendMessage(hwnd, LB_SETCURSEL, -1, 0); @@ -1335,18 +1697,21 @@ static void SelectListboxLine(HWND hwnd, int x, int y) int index; int size = GetTextSize(hwnd, NULL, 0); int id = GetDlgCtrlID(hwnd); + if (x == -1 || y == -1) { + DWORD msgpos = GetMessagePos(); + pt.x = GET_X_LPARAM(msgpos); + pt.y = GET_Y_LPARAM(msgpos); + } ScreenToClient(hwnd, &pt); - index = pt.y /size; + index = pt.y / size; SendMessage(hwnd, LB_SETCURSEL, index, 0); - if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2) - dbgpage[currpage].memsel = index; - else if (id == IDC_DBG_DASM || id == IDC_DBG_DASM2) - dbgpage[currpage].dasmsel = index; + dbgpage[currpage].selection = index; } static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hwnd; + static BOOL sizing = FALSE; switch (message) { case WM_INITDIALOG: { @@ -1396,14 +1761,26 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP return TRUE; case WM_DESTROY: { - RECT r; - if (GetWindowRect (hDlg, &r)) { - r.right -= r.left; - r.bottom -= r.top; - regsetint (NULL, "DebuggerPosX", r.left); - regsetint (NULL, "DebuggerPosY", r.top); - regsetint (NULL, "DebuggerPosW", r.right); - regsetint (NULL, "DebuggerPosH", r.bottom); + RECT *r; + int xoffset = 0, yoffset = 0; + WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) }; + MONITORINFO mi = { sizeof(MONITORINFO) }; + HMONITOR hmon = MonitorFromWindow(hDlg, MONITOR_DEFAULTTONEAREST); + if (hmon && GetMonitorInfo(hmon, &mi)) { + xoffset = mi.rcWork.left - mi.rcMonitor.left; + yoffset = mi.rcWork.top - mi.rcWork.top; + } + if (GetWindowPlacement (hDlg, &wp)) { + r = &wp.rcNormalPosition; + r->right -= r->left; + r->bottom -= r->top; + r->left += xoffset; + r->top += yoffset; + regsetint (NULL, "DebuggerPosX", r->left); + regsetint (NULL, "DebuggerPosY", r->top); + regsetint (NULL, "DebuggerPosW", r->right); + regsetint (NULL, "DebuggerPosH", r->bottom); + regsetint (NULL, "DebuggerMaximized", (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED)) ? 1 : 0); } hDbgWnd = 0; PostQuitMessage(0); @@ -1419,12 +1796,24 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP mmi->ptMinTrackSize.y = dbgwnd_miny; return TRUE; } + case WM_ENTERSIZEMOVE: + sizing = TRUE; + return FALSE; case WM_EXITSIZEMOVE: { AdjustDialog(hDlg); - ShowPage(currpage, TRUE); + ShowPage(currpage, TRUE); + sizing = FALSE; return TRUE; } + case WM_SIZE: + { + if (!sizing && (wParam == SIZE_MAXIMIZED || wParam == SIZE_RESTORED)) { + AdjustDialog(hDlg); + ShowPage(currpage, TRUE); + } + return TRUE; + } case WM_CTLCOLORSTATIC: { int id = GetDlgCtrlID((HWND)lParam); @@ -1443,6 +1832,11 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); return (LRESULT)GetSysColorBrush(COLOR_WINDOW); case WM_COMMAND: + if (!debugger_active) { + if (LOWORD(wParam) == IDC_DBG_AUTOSET && HIWORD(wParam) == BN_CLICKED) + SendMessage((HWND)lParam, BM_SETCHECK, dbgpage[currpage].autoset ? BST_CHECKED : BST_UNCHECKED, 0); + return TRUE; + } switch (LOWORD(wParam)) { case IDC_DBG_HELP: { @@ -1509,8 +1903,10 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP { int id = GetDlgCtrlID((HWND)wParam); if (id == IDC_DBG_MEM || id == IDC_DBG_MEM2 || id == IDC_DBG_DASM || id == IDC_DBG_DASM2) { - SelectListboxLine((HWND)wParam, LOWORD(lParam), HIWORD(lParam)); - ShowContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam)); + if (!hedit){ + SelectListboxLine((HWND)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + ShowContextMenu((HWND)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + } return TRUE; } break; @@ -1620,13 +2016,22 @@ static LRESULT CALLBACK DebuggerProc (HWND hDlg, UINT message, WPARAM wParam, LP SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); } TextOut(hdc, rc.left, rc.top, text, strlen(text)); + i = 0; + while (markinstr[i]) { + if (!strncmp(text + 34, markinstr[i], strlen(markinstr[i]))) { + MoveToEx(hdc, rc.left, rc.bottom - 1, NULL); + LineTo(hdc, rc.right, rc.bottom - 1); + break; + } + i++; + } if ((pdis->itemState) & (ODS_SELECTED)) DrawFocusRect(hdc, &rc); } else if (wParam == IDC_DBG_MEM || wParam == IDC_DBG_MEM2) { + TextOut(hdc, rc.left, rc.top, text, strlen(text)); if ((pdis->itemState) & (ODS_SELECTED)) DrawFocusRect(hdc, &rc); - TextOut(hdc, rc.left, rc.top, text, strlen(text)); } else TextOut(hdc, rc.left, rc.top, text, strlen(text)); @@ -1642,6 +2047,7 @@ int open_debug_window(void) { struct newresource *nr; + int maximized; if (hDbgWnd) return 0; @@ -1658,7 +2064,9 @@ int open_debug_window(void) return 0; InitPages(); ShowPage(0, TRUE); - ShowWindow(hDbgWnd, SW_SHOWNORMAL); + if (!regqueryint (NULL, "DebuggerMaximized", &maximized)) + maximized = 0; + ShowWindow(hDbgWnd, maximized ? SW_SHOWMAXIMIZED : SW_SHOW); UpdateWindow(hDbgWnd); update_debug_info(); return 1; @@ -1684,6 +2092,8 @@ int console_get_gui (char *out, int maxlen) } } if (inputfinished) { + if (dbgpage[currpage].autoset == 2) + dbgpage[currpage].autoset = 1; inputfinished = 0; if (useinternalcmd) { useinternalcmd = FALSE; @@ -1783,3 +2193,21 @@ void update_debug_info(void) } ShowPage(currpage, TRUE); } + +void update_disassembly(uae_u32 addr) +{ + if (!hDbgWnd || (pagetype != IDC_DBG_DASM && currpage != 0)) + return; + if (dbgpage[currpage].autoset) + dbgpage[currpage].autoset = 2; + dbgpage[currpage].dasmaddr = addr; + ShowDasm(0); +} + +void update_memdump(uae_u32 addr) +{ + if (!hDbgWnd || (pagetype != IDC_DBG_MEM && currpage != 0)) + return; + dbgpage[currpage].memaddr = addr; + ShowMem(0); +} diff --git a/od-win32/dxwarp_old.c b/od-win32/dxwarp_old.c new file mode 100755 index 00000000..6ec5523a --- /dev/null +++ b/od-win32/dxwarp_old.c @@ -0,0 +1,1950 @@ +/* + * UAE - The Ultimate Amiga Emulator + * + * Win32 DirectX Wrappers, to simplify (?) my life. + * + * Copyright 1999 Brian King, under GNU Public License + * + */ +#include "sysconfig.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "sysdeps.h" +#include "options.h" +#include "custom.h" +#include "memory.h" +#include "newcpu.h" +#include "picasso96.h" +#include "dxwrap.h" +#include "win32.h" +#include "win32gfx.h" +#include "machdep/rpt.h" + +static BOOL bColourKeyAvailable = FALSE; +static BOOL bOverlayAvailable = FALSE; +static DDCAPS_DX7 drivercaps, helcaps; +static DWORD overlayflags; +static DDOVERLAYFX overlayfx; +extern COLORREF g_dwBackgroundColor; +static int flipinterval_supported; + +#define dxwrite_log + +static HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surface) +{ + HRESULT hr2, hr; + DDSURFACEDESC2 surfacedesc; + + hr = IDirectDrawSurface7_Restore (surface); + if (SUCCEEDED(hr)) { + DDBLTFX bltfx; + memset (&bltfx, 0, sizeof (bltfx)); + bltfx.dwSize = sizeof (bltfx); + hr2 = IDirectDrawSurface7_Blt (surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); + if (FAILED(hr2)) { + static int crap = 0; + if (hr2 == DDERR_SURFACELOST) { + if (crap) + return hr; + crap = 1; + write_log ("Restore succeeded but following Blt failed with lost surface. Display driver bug?\n"); + return hr; + } + write_log ("Surface clear failed: %s\n", DXError (hr2)); + } + surfacedesc.dwSize = sizeof surfacedesc; + hr2 = IDirectDrawSurface7_Lock(surface, NULL, &surfacedesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); + if (SUCCEEDED(hr2)) { + write_log ("Surface Pointer: %p\n", surfacedesc.lpSurface); + IDirectDrawSurface7_Unlock(surface, NULL); + } + } + return hr; +} + + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static void clearsurface(int surface) +{ + DDBLTFX ddbltfx; + memset(&ddbltfx, 0, sizeof(ddbltfx)); + ddbltfx.dwFillColor = 0; + ddbltfx.dwSize = sizeof(ddbltfx); + DirectDraw_Blt(surface, NULL, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); +} + +void DirectDraw_ClearSurfaces(void) +{ + clearsurface(secondary_surface); + if(DirectDrawState.isoverlay) + clearsurface(overlay_surface); +} + +/* + * FUNCTION:ShowDDCaps + * + * PURPOSE:print out the DirectDraw Capabilities + * + * PARAMETERS: + * caps - DDCAPS_DX7 structure + * hw - flag indicating if this 'caps' is for real hardware or the HEL + * + * RETURNS: none + * + * NOTES:none + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static void ShowDDCaps( DDCAPS_DX7 caps, int hw ) +{ + static int shown = 0; + static BOOL reset_shown = FALSE; + if( currprefs.win32_logfile && shown >= 4 && !reset_shown) + { + shown = 0; + reset_shown = TRUE; + } + + if( shown < 2) + { + dxwrite_log ( "DirectDraw Capabilities for %s:\n", hw ? "Display Driver Hardware" : "Display Driver Emulation Layer" ); + if( caps.dwCaps & DDCAPS_BLT ) + dxwrite_log ( "DDCAPS_BLT - Capable of blitting\n" ); + if( caps.dwCaps & DDCAPS_BLTCOLORFILL ) + dxwrite_log ( "DDCAPS_BLTCOLORFILL - Color filling with blitter\n" ); + if( caps.dwCaps & DDCAPS_BLTSTRETCH ) + dxwrite_log ( "DDCAPS_BLTSTRETCH - Stretch blitting\n" ); + if( caps.dwCaps & DDCAPS_CANBLTSYSMEM ) + dxwrite_log ( "DDCAPS_CANBLTSYSMEM - Blits from system memory\n" ); + if( caps.dwCaps & DDCAPS_CANCLIP ) + dxwrite_log ( "DDCAPS_CANCLIP - Can clip while blitting\n" ); + if( caps.dwCaps & DDCAPS_CANCLIPSTRETCHED ) + dxwrite_log ( "DDCAPS_CANCLIPSTRETCHED - Can clip while stretch-blitting\n" ); + if( caps.dwCaps & DDCAPS_COLORKEY ) + { + dxwrite_log ( "DDCAPS_COLORKEY - Can color-key with blits/overlays\n" ); + bColourKeyAvailable = TRUE; + } + if( caps.dwCaps & DDCAPS_GDI ) + dxwrite_log ( "DDCAPS_GDI - Display h/w shared with GDI\n" ); + if( caps.dwCaps & DDCAPS_NOHARDWARE ) + dxwrite_log ( "DDCAPS_NOHARDWARE - no h/w support!\n" ); + if( caps.dwCaps & DDCAPS_OVERLAY ) + { + dxwrite_log ( "DDCAPS_OVERLAY - support for %d overlay(s)\n", caps.dwMaxVisibleOverlays ); + if( bColourKeyAvailable ) + { + if( caps.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY ) + { + dxwrite_log ( "DDCKEYCAPS_DESTOVERLAY - colour-keyed overlays\n" ); + bOverlayAvailable = TRUE; + } + } + } + if( caps.dwCaps & DDCAPS_OVERLAYFOURCC ) + dxwrite_log ( "DDCAPS_OVERLAYFOURCC - overlay can do color-space conversions\n" ); + if( caps.dwCaps & DDCAPS_OVERLAYSTRETCH ) + dxwrite_log ( "DDCAPS_OVERLAYSTRETCH - overlay can stretch with min=%d/max=%d\n", caps.dwMinOverlayStretch, caps.dwMaxOverlayStretch ); + if( caps.dwCaps & DDCAPS_VBI ) + dxwrite_log ( "DDCAPS_VBI - h/w can generate a vertical-blanking interrupt\n" ); + if( caps.dwCaps2 & DDCAPS2_CERTIFIED ) + dxwrite_log ( "DDCAPS2_CERTIFIED - certified driver\n" ); + if( caps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED ) + dxwrite_log ( "DDCAPS2_CANRENDERWINDOWED - GDI windows can be seen when in full-screen\n" ); + if( caps.dwCaps2 & DDCAPS2_NOPAGELOCKREQUIRED ) + dxwrite_log ( "DDCAPS2_NOPAGELOCKREQUIRED - no page locking needed for DMA blits\n" ); + if( caps.dwCaps2 & DDCAPS2_FLIPNOVSYNC ) + dxwrite_log ( "DDCAPS2_FLIPNOVSYNC - can pass DDFLIP_NOVSYNC to Flip calls\n" ); + if( caps.dwCaps2 & DDCAPS2_FLIPINTERVAL ) { + dxwrite_log ( "DDCAPS2_FLIPINTERVAL - can pass DDFLIP_INTERVALx to Flip calls\n" ); + flipinterval_supported = 1; + } + + dxwrite_log ( "Video memory: %d/%d\n", caps.dwVidMemFree, caps.dwVidMemTotal ); + } + shown++; +} + +const char *DXError (HRESULT ddrval) +{ + static char dderr[1000]; + sprintf(dderr, "%08.8X S=%d F=%04.4X C=%04.4X (%d) (%s)", + ddrval, (ddrval & 0x80000000) ? 1 : 0, + HRESULT_FACILITY(ddrval), + HRESULT_CODE(ddrval), + HRESULT_CODE(ddrval), + DXGetErrorDescription9 (ddrval)); + return dderr; +} + +struct DirectDrawSurfaceMapper DirectDrawState; + +static int lockcnt = 0; + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static int LockStub( surface_type_e type ) +{ + int result = 0; + HRESULT ddrval; + LPDIRECTDRAWSURFACE7 surface; + LPDDSURFACEDESC2 surfacedesc; + + switch( type ) + { + case primary_surface: + surface = DirectDrawState.primary.surface; + surfacedesc = &DirectDrawState.primary.desc; + break; + case secondary_surface: + surface = DirectDrawState.secondary.surface; + surfacedesc = &DirectDrawState.secondary.desc; + break; + case tertiary_surface: + surface = DirectDrawState.tertiary.surface; + surfacedesc = &DirectDrawState.tertiary.desc; + break; + case temporary_surface: + surface = DirectDrawState.temporary.surface; + surfacedesc = &DirectDrawState.temporary.desc; + break; + case overlay_surface: + surface = DirectDrawState.overlay.surface; + surfacedesc = &DirectDrawState.overlay.desc; + break; + } + + if(lockcnt) + { +#ifdef _DEBUG + //DebugBreak(); +#endif + return 1; + } + + if(type == secondary_surface && DirectDrawState.flipping != single_buffer) + { + IDirectDrawSurface7_Restore(DirectDrawState.primary.surface); + } + + while (FAILED(ddrval = IDirectDrawSurface7_Lock(surface, NULL, surfacedesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) + { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (surface); + if (FAILED(ddrval)) + break; + } + else if (ddrval != DDERR_SURFACEBUSY) + { + write_log ("lpDDS->Lock() failed - %s\n", DXError (ddrval)); + break; + } + } + if(SUCCEEDED(ddrval)) { + static int warned = 10; + DWORD_PTR pixels = (DWORD_PTR)(surfacedesc->lpSurface); + if (warned > 0 && (pixels & 7)) { + write_log ("bogus surface pointer %x!\n", pixels); + warned--; + } + lockcnt++; + result = 1; + } + return result; +} + +/* For a given surface-type, update our DirectDrawState structure */ +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +int DirectDraw_SurfaceLock(surface_type_e surface_type) +{ + int result = 0; + + if (surface_type == lockable_surface) + surface_type = DirectDraw_GetLockableType(); + + switch(surface_type) + { + case primary_surface: + DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); + result = LockStub(surface_type); + break; + case secondary_surface: + DirectDrawState.secondary.desc.dwSize = sizeof(DDSURFACEDESC2); + result = LockStub(surface_type); + break; + case tertiary_surface: + DirectDrawState.tertiary.desc.dwSize = sizeof(DDSURFACEDESC2); + result = LockStub(surface_type); + break; + case temporary_surface: + DirectDrawState.temporary.desc.dwSize = sizeof(DDSURFACEDESC2); + result = LockStub(surface_type); + break; + case overlay_surface: + DirectDrawState.overlay.desc.dwSize = sizeof(DDSURFACEDESC2); + result = LockStub(surface_type); + case lockable_surface: + case invalid_surface: + default: + + break; + } + DirectDrawState.locked = result; + + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +char *DirectDraw_GetSurfacePointer(void) +{ + char *pixels = NULL; + + /* Make sure that somebody has done a lock before returning the lpSurface member */ + if(lockcnt) + pixels = DirectDrawState.lockable.lpdesc->lpSurface; + return pixels; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +LONG DirectDraw_GetSurfacePitch(void) +{ + LONG pitch = 0; + + pitch = DirectDrawState.lockable.lpdesc->lPitch; + return pitch; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_GetPixelFormatFlags(void) +{ + DWORD flags = 0; + flags = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwFlags; + return flags; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_GetSurfaceFlags(void) +{ + DWORD flags = 0; + flags = DirectDrawState.lockable.lpdesc->dwFlags; + return flags; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_GetSurfaceBitCount(void) +{ + DWORD bits = 0; + //?????JGI begin: + if(DirectDrawState.lockable.lpdesc) + bits = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRGBBitCount; + else + bits = DirectDrawState.current.desc.ddpfPixelFormat.dwRGBBitCount; + //?????JGI end. + return bits; +} + +/* + * FUNCTION:DirectDraw_GetPrimaryBitCount + * + * PURPOSE:Return the bit-depth of the primary surface + * + * PARAMETERS: none + * + * RETURNS: bit-depth + * + * NOTES: + * + * HISTORY: + * 2001.08.25 Brian King Creation + * + */ +DWORD DirectDraw_GetPrimaryBitCount(void) +{ + DWORD bits = 0; + memset(&DirectDrawState.primary.desc,0,sizeof(DirectDrawState.primary.desc)); + DirectDrawState.primary.desc.dwSize = sizeof(DirectDrawState.primary.desc); + + IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &DirectDrawState.primary.desc); + bits = DirectDrawState.primary.desc.ddpfPixelFormat.dwRGBBitCount; + return bits; +} + +void DirectDraw_GetPrimaryWidthHeight(int *w, int *h) +{ + memset(&DirectDrawState.primary.desc,0,sizeof(DirectDrawState.primary.desc)); + DirectDrawState.primary.desc.dwSize = sizeof(DirectDrawState.primary.desc); + + IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &DirectDrawState.primary.desc); + *w = DirectDrawState.primary.desc.dwWidth; + *h = DirectDrawState.primary.desc.dwHeight; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_GetPixelFormatBitMask(DirectDraw_Mask_e mask) +{ + DWORD result = 0; + switch(mask) + { + case red_mask: + result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRBitMask; + break; + case green_mask: + result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwGBitMask; + break; + case blue_mask: + result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwBBitMask; + break; + } + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +surface_type_e DirectDraw_GetLockableType(void) +{ + return DirectDrawState.surface_type; +} + +/* + * FUNCTION:DirectDraw_IsLocked + * + * PURPOSE:Return whether we're currently locked or unlocked + * + * PARAMETERS: none + * + * RETURNS: TRUE if already locked, FALSE otherwise + * + * NOTES:Used by DX_Blit to possibly unlock during Blit operation + * + * HISTORY: + * 2000.04.30 Brian King Creation + * + */ +BOOL DirectDraw_IsLocked(void) +{ + return DirectDrawState.locked ? TRUE : FALSE; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static surface_type_e try_surface_locks(int want_fullscreen) +{ + surface_type_e result = invalid_surface; + + if(DirectDrawState.isoverlay && DirectDraw_SurfaceLock(overlay_surface)) + { + result = overlay_surface; + write_log ("try_surface_locks() returning overlay\n"); + } + else if(want_fullscreen && WIN32GFX_IsPicassoScreen()) + { + if(DirectDraw_SurfaceLock(primary_surface)) + { + result = primary_surface; + write_log ("try_surface_locks() returning primary\n"); + } + else if(DirectDraw_SurfaceLock(secondary_surface)) + { + result = secondary_surface; + write_log ("try_surface_locks() returning secondary\n"); + } + } + else + { + if(DirectDraw_SurfaceLock(secondary_surface)) + { + result = secondary_surface; + write_log ("try_surface_locks() returning secondary\n"); + } + } + + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES:Named this way for historical reasons + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +void ddraw_unlockscr(void) +{ + if(lockcnt > 0) { + lockcnt--; + IDirectDrawSurface7_Unlock(DirectDrawState.lockable.surface, + DirectDrawState.lockable.lpdesc->lpSurface); + DirectDrawState.locked = FALSE; + } +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +int DirectDraw_Start(GUID *guid) +{ + HRESULT ddrval; + /* Prepare our DirectDrawState structure */ + ZeroMemory(&DirectDrawState, sizeof(DirectDrawState)); + ZeroMemory(&drivercaps, sizeof(drivercaps)); + ZeroMemory(&helcaps, sizeof(helcaps)); + drivercaps.dwSize = sizeof(drivercaps); + helcaps.dwSize = sizeof(helcaps); + + ddrval = DirectDrawCreate(guid, &DirectDrawState.directdraw.ddx, NULL); + if (FAILED(ddrval)) { + if (guid != NULL) + return 0; + goto oops; + } + + DirectDrawState.initialized = TRUE; + + ddrval = IDirectDraw_QueryInterface(DirectDrawState.directdraw.ddx, + &IID_IDirectDraw7, (LPVOID *)&DirectDrawState.directdraw.dd); + if(FAILED(ddrval)) { + gui_message("start_ddraw(): DirectX 7 or newer required"); + DirectDraw_Release(); + return 0; + } + + DirectDraw_GetCaps(&drivercaps, &helcaps); + ShowDDCaps(drivercaps, 1); + ShowDDCaps(helcaps, 0); + if (SUCCEEDED(DirectDraw_GetDisplayMode ())) + return 1; + if (guid != NULL) { + DirectDraw_Release (); + return 0; + } + + oops: + gui_message ("start_ddraw(): DirectDraw initialization failed with %s\n", DXError (ddrval)); + DirectDraw_Release(); + return 0; +} + +#define releaser(x,y) if( x ) { y( x ); x = NULL; } + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +void DirectDraw_Release(void) +{ + releaser(DirectDrawState.lpDDC, IDirectDrawClipper_Release); + releaser(DirectDrawState.lpDDP, IDirectDrawPalette_Release); + + if (DirectDrawState.directdraw.dd && DirectDrawState.modeset) { + IDirectDraw7_RestoreDisplayMode(DirectDrawState.directdraw.dd); + IDirectDraw7_SetCooperativeLevel(DirectDrawState.directdraw.dd, hAmigaWnd, DDSCL_NORMAL); + } + DirectDrawState.modeset = 0; + + releaser(DirectDrawState.overlay.surface, IDirectDrawSurface7_Release); + releaser(DirectDrawState.primary.surface, IDirectDrawSurface7_Release); + + if(DirectDrawState.flipping == single_buffer) + releaser(DirectDrawState.secondary.surface, IDirectDrawSurface7_Release); + + releaser(DirectDrawState.directdraw.dd, IDirectDraw_Release); + + DirectDrawState.lockable.lpdesc = NULL; + DirectDrawState.lockable.lpdesc = NULL; + DirectDrawState.lockable.surface = NULL; + DirectDrawState.lockable.surface = NULL; + + DirectDrawState.surface_type = invalid_surface; + DirectDrawState.initialized = FALSE; + DirectDrawState.isoverlay = FALSE; +} + +/* + * FUNCTION:DirectDraw_SetCooperativeLevel + * + * PURPOSE:Wrapper for setting the cooperative level (fullscreen or normal) + * + * PARAMETERS: + * window Window to set the cooperative level for + * want_fullscreen fullscreen mode flag + * + * RETURNS: result of underlying DirectDraw call + * + * NOTES: Updates the .fullscreen and .window members. + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_SetCooperativeLevel(HWND window, int want_fullscreen) +{ + HRESULT ddrval; + + ddrval = IDirectDraw7_SetCooperativeLevel(DirectDrawState.directdraw.dd, + window, want_fullscreen ? + DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); + if(SUCCEEDED(ddrval)) { + DirectDrawState.fullscreen = want_fullscreen; + DirectDrawState.window = window; + } + return ddrval; +} + +/* + * FUNCTION:DirectDraw_GetCooperativeLevel + * + * PURPOSE:Wrapper for setting the cooperative level (fullscreen or normal) + * + * PARAMETERS: + * window Window to set the cooperative level for + * want_fullscreen fullscreen mode flag + * + * RETURNS: result of underlying DirectDraw call + * + * NOTES: Updates the .fullscreen and .window members. + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +BOOL DirectDraw_GetCooperativeLevel(HWND *window, int *fullscreen) +{ + BOOL result = FALSE; + + if(DirectDrawState.initialized) { + *fullscreen = DirectDrawState.fullscreen; + *window = DirectDrawState.window; + result = TRUE; + } + return result; +} + +/* + * FUNCTION:DirectDraw_SetDisplayMode + * + * PURPOSE:Change the display-mode to width x height pixels, with a given + * vertical refresh-rate. + * + * PARAMETERS: + * width - width of display in pixels + * height - height of display in pixels + * freq - vertical refresh-rate in Hz + * + * RETURNS: + * ddrval - HRESULT indicating success (DD_OK) or failure + * + * NOTES:The freq parameter is only obeyed on when we're using DirectX 6 + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_SetDisplayMode(int width, int height, int bits, int freq) +{ + HRESULT ddrval; + + ddrval = IDirectDraw7_SetDisplayMode(DirectDrawState.directdraw.dd, + width, height, bits, freq, 0); + DirectDrawState.modeset = 1; + return ddrval; +} + +/* + * FUNCTION:DirectDraw_GetDisplayMode + * + * PURPOSE:Get the display-mode characteristics. + * + * PARAMETERS: none + * + * RETURNS: + * ddrval - HRESULT indicating success (DD_OK) or failure + * + * NOTES:none + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_GetDisplayMode(void) +{ + HRESULT ddrval; + + /* We fill in the current.desc in all cases */ + DirectDrawState.current.desc.dwSize = sizeof(DDSURFACEDESC2); + ddrval = IDirectDraw7_GetDisplayMode(DirectDrawState.directdraw.dd, + &DirectDrawState.current.desc); + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_GetCaps(DDCAPS_DX7 *driver_caps, DDCAPS_DX7 *hel_caps) +{ + HRESULT ddrval; + + ddrval = IDirectDraw7_GetCaps(DirectDrawState.directdraw.dd, + driver_caps, hel_caps); + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_CreateClipper(void) +{ + HRESULT ddrval; + ddrval = IDirectDraw7_CreateClipper(DirectDrawState.directdraw.dd, + 0, &DirectDrawState.lpDDC, NULL); + return ddrval; +} + +static DWORD ConvertGDIColor(COLORREF dwGDIColor) +{ + COLORREF rgbT; + HDC hdc; + DWORD dw = CLR_INVALID; + DDSURFACEDESC2 ddsd,pdds; + HRESULT hr; + + memset(&pdds,0,sizeof(pdds)); + pdds.dwSize = sizeof(pdds); + + IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &pdds); + + // Use GDI SetPixel to color match for us + if(dwGDIColor != CLR_INVALID && SUCCEEDED(IDirectDrawSurface7_GetDC(DirectDrawState.primary.surface, &hdc))) { + rgbT = GetPixel(hdc, 0, 0); // Save current pixel value + SetPixel(hdc, 0, 0, dwGDIColor); // Set our value + IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface,hdc); + } + + // Now lock the surface so we can read back the converted color + ddsd.dwSize = sizeof(ddsd); + hr = IDirectDrawSurface7_Lock(DirectDrawState.primary.surface, NULL, &ddsd, DDLOCK_WAIT, NULL ); + if(SUCCEEDED(hr)) { + dw = *(DWORD *) ddsd.lpSurface; + if(ddsd.ddpfPixelFormat.dwRGBBitCount < 32) // Mask it to bpp + dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; + IDirectDrawSurface7_Unlock(DirectDrawState.primary.surface,NULL); + } + + // Now put the color that was there back. + if(dwGDIColor != CLR_INVALID && SUCCEEDED(IDirectDrawSurface7_GetDC(DirectDrawState.primary.surface,&hdc))) { + SetPixel(hdc, 0, 0, rgbT); + IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface,hdc); + } + + return dw; +} + + +HRESULT DirectDraw_CreateOverlaySurface(int width, int height, int bits, int type) +{ + DDSURFACEDESC2 ddsd; + DDPIXELFORMAT ddpfOverlayFormat; + HRESULT ddrval = DDERR_UNSUPPORTED; + DWORD dwDDSColor; + DWORD flags = DDPF_RGB; + + ZeroMemory(&ddpfOverlayFormat, sizeof(ddpfOverlayFormat)); + ddpfOverlayFormat.dwSize = sizeof(ddpfOverlayFormat); + ZeroMemory(&ddsd, sizeof(ddsd)); + + if (bOverlayAvailable) { + write_log ( "CreateOverlaySurface being called with %d-bits!\n", bits ); + if(bits == 16) { + // Set the overlay format to 16 bit RGB 5:6:5 + ddpfOverlayFormat.dwFlags = flags; + ddpfOverlayFormat.dwRGBBitCount = 16; + ddpfOverlayFormat.dwRBitMask = 0xF800; + ddpfOverlayFormat.dwGBitMask = 0x07E0; + ddpfOverlayFormat.dwBBitMask = 0x001F; + } else if(bits == 32) { + // Set the overlay format to 32 bit ARGB 8:8:8:8 + ddpfOverlayFormat.dwFlags = flags; + ddpfOverlayFormat.dwRGBBitCount = 32; + ddpfOverlayFormat.dwRBitMask = 0x00FF0000; + ddpfOverlayFormat.dwGBitMask = 0x0000FF00; + ddpfOverlayFormat.dwBBitMask = 0x000000FF; + } else if(bits == 8) { + // Set the overlay format to 8 bit palette + ddpfOverlayFormat.dwFlags = flags | DDPF_PALETTEINDEXED8; + ddpfOverlayFormat.dwRGBBitCount = 8; + ddpfOverlayFormat.dwRBitMask = 0x00000000; + ddpfOverlayFormat.dwGBitMask = 0x00000000; + ddpfOverlayFormat.dwBBitMask = 0x00000000; + } else { + // We don't handle this case... + return DDERR_INVALIDPIXELFORMAT; + } + + // Setup the overlay surface's attributes in the surface descriptor + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; + ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; + ddsd.dwWidth = width; + ddsd.dwHeight = height; + ddsd.ddpfPixelFormat = ddpfOverlayFormat; + + ZeroMemory(&overlayfx, sizeof(overlayfx)); + overlayfx.dwSize = sizeof(overlayfx); + overlayflags = DDOVER_SHOW | DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE; + + dwDDSColor = ConvertGDIColor(g_dwBackgroundColor); + overlayfx.dckDestColorkey.dwColorSpaceLowValue = dwDDSColor; + overlayfx.dckDestColorkey.dwColorSpaceHighValue = dwDDSColor; + + // Attempt to create the surface with theses settings + ddrval = IDirectDraw7_CreateSurface (DirectDrawState.directdraw.dd, &ddsd, &DirectDrawState.overlay.surface, NULL); + if(SUCCEEDED(ddrval)) { + DirectDrawState.isoverlay = 1; + } else { + DirectDrawState.isoverlay = 0; + } + } else { + write_log ( "CreateOverlaySurface being called, but no overlay support with this card...!\n" ); + } + return ddrval; +} + + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_CreateSurface(int width, int height) +{ + HRESULT ddrval; + DWORD xtraflag = 0; + + DirectDrawState.flipping = single_buffer; + + if (DirectDrawState.fullscreen) { // Create a flipping pair! + ZeroMemory (&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); + DirectDrawState.primary.desc.dwSize = sizeof (DDSURFACEDESC2); + DirectDrawState.primary.desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; + DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; + DirectDrawState.primary.desc.dwBackBufferCount = 2; + ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, + &DirectDrawState.primary.desc, &DirectDrawState.primary.surface, NULL); + if (FAILED(ddrval)) { + // Create a non-flipping pair, since the flipping pair creation failed... + ZeroMemory (&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); + DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); + DirectDrawState.primary.desc.dwFlags = DDSD_CAPS; + DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, + &DirectDrawState.primary.desc, + &DirectDrawState.primary.surface, + NULL); + } else { + DirectDrawState.flipping = triple_buffer; + } + clearsurface (primary_surface); + } else { + // We're not full-screen, so you cannot create a flipping pair... + ZeroMemory(&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); + DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); + DirectDrawState.primary.desc.dwFlags = DDSD_CAPS; + DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, + &DirectDrawState.primary.desc, &DirectDrawState.primary.surface, NULL); + } + + if(FAILED(ddrval)) { + goto errout; + } else { + write_log ( "DDRAW: Primary %ssurface created in video-memory\n", + DirectDrawState.flipping != single_buffer ? "flipping " : ""); + } + + // Check if we can access the back-buffer of our flipping-pair (if present) + if(DirectDrawState.flipping != single_buffer) { + DDSCAPS2 ddSCaps; + ZeroMemory(&ddSCaps, sizeof(ddSCaps)); + ddSCaps.dwCaps = DDSCAPS_BACKBUFFER; + + ddrval = IDirectDrawSurface7_GetAttachedSurface(DirectDrawState.primary.surface, &ddSCaps, &DirectDrawState.secondary.surface); + if(SUCCEEDED(ddrval)) { + /* get third buffer */ + ZeroMemory(&ddSCaps, sizeof(ddSCaps)); + ddSCaps.dwCaps = DDSCAPS_FLIP; + + ddrval = IDirectDrawSurface7_GetAttachedSurface(DirectDrawState.secondary.surface, &ddSCaps, &DirectDrawState.tertiary.surface); + if(SUCCEEDED(ddrval)) { + clearsurface (tertiary_surface); + } else { + DirectDrawState.flipping = single_buffer; + } + } else { + DirectDrawState.flipping = single_buffer; + } + } + + // We always want a secondary-buffer when creating our primary-surface. If we're a flipping pair, + // the secondary buffer is already allocated. If we failed to create a flipping pair, or because + // we're not full-screen, then lets create ourselves a back-buffer manually. + if(DirectDrawState.flipping == single_buffer) { + ZeroMemory(&DirectDrawState.secondary.desc, sizeof(DDSURFACEDESC2)); + DirectDrawState.secondary.desc.dwSize = sizeof(DDSURFACEDESC2); + DirectDrawState.secondary.desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + DirectDrawState.secondary.desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | xtraflag; + DirectDrawState.secondary.desc.dwWidth = width; + DirectDrawState.secondary.desc.dwHeight = height; + ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, + &DirectDrawState.secondary.desc, &DirectDrawState.secondary.surface, NULL); + if(FAILED(ddrval)) { + write_log ( "DDRAW:Secondary surface creation attempt #1 failed with %s\n", DXError(ddrval)); + DirectDrawState.secondary.desc.ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY; + DirectDrawState.secondary.desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; + ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, + &DirectDrawState.secondary.desc, &DirectDrawState.secondary.surface, NULL); + if(SUCCEEDED(ddrval)) + write_log ("DDRAW: Secondary surface created in plain system-memory\n"); + else + goto errout; + } else { + write_log ("DDRAW: Secondary surface created in video-memory\n"); + } + } + DirectDraw_ClearSurfaces (); +errout: + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +int DirectDraw_DetermineLocking( int wantfull ) +{ + int result = 0; + + switch(DirectDrawState.surface_type = try_surface_locks(wantfull)) + { + case invalid_surface: + case lockable_surface: + DirectDrawState.lockable.lpdesc = NULL; + DirectDrawState.lockable.lpdesc = NULL; + DirectDrawState.lockable.surface = NULL; + DirectDrawState.lockable.surface = NULL; + write_log ("set_ddraw: Couldn't lock primary, and no secondary available.\n"); + break; + case primary_surface: + DirectDrawState.lockable.lpdesc = &DirectDrawState.primary.desc; + DirectDrawState.lockable.lpdesc = &DirectDrawState.primary.desc; + DirectDrawState.lockable.surface = DirectDrawState.primary.surface; + DirectDrawState.lockable.surface = DirectDrawState.primary.surface; + result = 1; + break; + case overlay_surface: + DirectDrawState.lockable.lpdesc = &DirectDrawState.overlay.desc; + DirectDrawState.lockable.lpdesc = &DirectDrawState.overlay.desc; + DirectDrawState.lockable.surface = DirectDrawState.overlay.surface; + DirectDrawState.lockable.surface = DirectDrawState.overlay.surface; + result = 1; + break; + case secondary_surface: + DirectDrawState.lockable.lpdesc = &DirectDrawState.secondary.desc; + DirectDrawState.lockable.lpdesc = &DirectDrawState.secondary.desc; + DirectDrawState.lockable.surface = DirectDrawState.secondary.surface; + DirectDrawState.lockable.surface = DirectDrawState.secondary.surface; + result = 1; + break; + case tertiary_surface: + DirectDrawState.lockable.lpdesc = &DirectDrawState.tertiary.desc; + DirectDrawState.lockable.lpdesc = &DirectDrawState.tertiary.desc; + DirectDrawState.lockable.surface = DirectDrawState.tertiary.surface; + DirectDrawState.lockable.surface = DirectDrawState.tertiary.surface; + result = 1; + break; + } + + if(DirectDrawState.lockable.surface) + DirectDraw_SurfaceUnlock(); + + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_SetClipper(HWND hWnd) +{ + HRESULT ddrval; + + ddrval = IDirectDrawSurface7_SetClipper(DirectDrawState.primary.surface, + hWnd ? DirectDrawState.lpDDC : NULL); + if(hWnd && SUCCEEDED(ddrval)) + ddrval = IDirectDrawClipper_SetHWnd(DirectDrawState.lpDDC, 0, hWnd); + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_GetClipList(LPRGNDATA cliplist, LPDWORD size) +{ + HRESULT ddrval; + + ddrval = IDirectDrawClipper_GetClipList(DirectDrawState.lpDDC, NULL, cliplist, size); + + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +int DirectDraw_GetBytesPerPixel(void) +{ + if(DirectDrawState.lockable.lpdesc) + return (DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRGBBitCount + 7) >> 3; + return 0; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_SetPalette(int remove) +{ + HRESULT ddrval; + if (DirectDrawState.primary.surface == NULL) + return DDERR_SURFACELOST; + ddrval = IDirectDrawSurface7_SetPalette (DirectDrawState.primary.surface, + remove ? NULL : DirectDrawState.lpDDP); + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (DirectDrawState.primary.surface); + if (SUCCEEDED(ddrval)) { + ddrval = IDirectDrawSurface7_SetPalette (DirectDrawState.primary.surface, + remove ? NULL : DirectDrawState.lpDDP); + } + } + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_CreatePalette(LPPALETTEENTRY pal) +{ + HRESULT ddrval; + ddrval = IDirectDraw_CreatePalette(DirectDrawState.directdraw.dd, + DDPCAPS_8BIT | DDPCAPS_ALLOW256, pal, &DirectDrawState.lpDDP, NULL); + if(SUCCEEDED(ddrval)) + ddrval = DirectDraw_SetPalette(0); + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_SetPaletteEntries(int start, int count, PALETTEENTRY *palette) +{ + HRESULT ddrval = DDERR_NOPALETTEATTACHED; + if(DirectDrawState.lpDDP) + ddrval = IDirectDrawPalette_SetEntries(DirectDrawState.lpDDP, 0, start, count, palette); + return ddrval; +} + +/* Return one of the pixel formats declared in picasso96.h if the surface + * is usable for us, or RGBFB_NONE if it is not usable. */ +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface) +{ + int surface_is = 0; + DDPIXELFORMAT *pfp = NULL; + DWORD r, g, b; + DWORD surf_flags; + + surf_flags = surface->dwFlags; + pfp = &surface->ddpfPixelFormat; + + if((surf_flags & DDSD_PIXELFORMAT) == 0x0) + return RGBFB_NONE; + + if ((pfp->dwFlags & DDPF_RGB) == 0) + return RGBFB_NONE; + + r = pfp->dwRBitMask; + g = pfp->dwGBitMask; + b = pfp->dwBBitMask; + switch (pfp->dwRGBBitCount) { + case 8: + if ((pfp->dwFlags & DDPF_PALETTEINDEXED8) != 0) + return RGBFB_CHUNKY; + break; + + case 16: + if (r == 0xF800 && g == 0x07E0 && b == 0x001F) + return RGBFB_R5G6B5PC; + if (r == 0x7C00 && g == 0x03E0 && b == 0x001F) + return RGBFB_R5G5B5PC; + if (b == 0xF800 && g == 0x07E0 && r == 0x001F) + return RGBFB_B5G6R5PC; + if (b == 0x7C00 && g == 0x03E0 && r == 0x001F) + return RGBFB_B5G5R5PC; + /* This happens under NT - with r == b == g == 0 !!! */ + write_log ("Unknown 16 bit format %d %d %d\n", r, g, b); + break; + + case 24: + if (r == 0xFF0000 && g == 0x00FF00 && b == 0x0000FF) + return RGBFB_B8G8R8; + if (r == 0x0000FF && g == 0x00FF00 && b == 0xFF0000) + return RGBFB_R8G8B8; + break; + + case 32: + if (r == 0x00FF0000 && g == 0x0000FF00 && b == 0x000000FF) + return RGBFB_B8G8R8A8; + if (r == 0x000000FF && g == 0x0000FF00 && b == 0x00FF0000) + return RGBFB_R8G8B8A8; + if (r == 0xFF000000 && g == 0x00FF0000 && b == 0x0000FF00) + return RGBFB_A8B8G8R8; + if (r == 0x0000FF00 && g == 0x00FF0000 && b == 0xFF000000) + return RGBFB_A8R8G8B8; + break; + + default: + write_log ("Unknown %d bit format %d %d %d\n", pfp->dwRGBBitCount, r, g, b); + break; + } + return RGBFB_NONE; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +RGBFTYPE DirectDraw_GetPixelFormat(void) +{ + RGBFTYPE type; + if(DirectDrawState.lockable.lpdesc) + type = DirectDraw_GetSurfacePixelFormat(DirectDrawState.lockable.lpdesc); + else + type = DirectDraw_GetSurfacePixelFormat(&DirectDrawState.current.desc); + return type; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_CurrentWidth(void) +{ + DWORD width; + width = DirectDrawState.current.desc.dwWidth; + return width; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +DWORD DirectDraw_CurrentHeight(void) +{ + DWORD height; + height = DirectDrawState.current.desc.dwHeight; + return height; +} + +int DirectDraw_GetVerticalBlankStatus (void) +{ + BOOL status; + if (FAILED(IDirectDraw7_GetVerticalBlankStatus (DirectDrawState.directdraw.dd, &status))) + return -1; + return status; +} + +DWORD DirectDraw_CurrentRefreshRate(void) +{ + DWORD height; + height = DirectDrawState.current.desc.dwRefreshRate; + return height; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static int DirectDraw_BltFastStub4(LPDIRECTDRAWSURFACE7 dstsurf, DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect) +{ + int result = 0; + HRESULT ddrval; + + while(FAILED(ddrval = IDirectDrawSurface7_BltFast(dstsurf, x, y, srcsurf, srcrect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (dstsurf); + if (FAILED(ddrval)) + break; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log ("BltFastStub7(): DirectDrawSURFACE7_BltFast() failed with %s\n", DXError (ddrval)); + break; + } + } + if(SUCCEEDED(ddrval)) + result = 1; + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_BltFast(surface_type_e dsttype, DWORD left, DWORD top, surface_type_e srctype, LPRECT srcrect) +{ + LPDIRECTDRAWSURFACE7 lpDDS4_dst, lpDDS4_src; + if(dsttype == primary_surface) { + lpDDS4_dst = DirectDrawState.primary.surface; + } else if (dsttype == temporary_surface) { + lpDDS4_dst = DirectDrawState.temporary.surface; + } else { + lpDDS4_dst = DirectDrawState.secondary.surface; + } + if(srctype == primary_surface) { + lpDDS4_src = DirectDrawState.primary.surface; + } else if (srctype == temporary_surface) { + lpDDS4_src = DirectDrawState.temporary.surface; + } else { + lpDDS4_src = DirectDrawState.secondary.surface; + } + return DirectDraw_BltFastStub4(lpDDS4_dst, left, top, lpDDS4_src, srcrect); +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +static HRESULT DirectDraw_BltStub(LPDIRECTDRAWSURFACE7 dstsurf, LPRECT dstrect, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect, DWORD flags, LPDDBLTFX ddbltfx) +{ + int result = 0, errcnt = 0; + HRESULT ddrval; + + while(FAILED(ddrval = IDirectDrawSurface7_Blt(dstsurf, dstrect, srcsurf, srcrect, flags, ddbltfx))) { + if (ddrval == DDERR_SURFACELOST) { + if (errcnt > 10) + return 1; + errcnt++; + ddrval = restoresurface (dstsurf); + if (FAILED(ddrval)) { + break; + } + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log ("BltStub(): DirectDrawSURFACE7_Blt() failed with %s\n", DXError (ddrval)); + break; + } + } + return ddrval; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ + +int DirectDraw_Flip(int wait) +{ + int result = 0; + HRESULT ddrval = DD_OK; + DWORD flags = DDFLIP_WAIT; + static int skip; + frame_time_t start; + + start = read_processor_time (); + if (DirectDrawState.flipping == triple_buffer) { + if (!currprefs.gfx_afullscreen && !currprefs.gfx_avsync) { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); + } else if (currprefs.gfx_avsync) { + if (vblank_skip >= 0) { + skip++; + if (vblank_skip > skip) { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); + } else { + skip = 0; + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + idletime += read_processor_time() - start; + } + } else { + if (flipinterval_supported) { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_INTERVAL2); + idletime += read_processor_time() - start; + } else { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + idletime += read_processor_time() - start; + result = DirectDraw_BltFast(tertiary_surface, 0, 0, primary_surface, NULL); + start = read_processor_time(); + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + idletime += read_processor_time() - start; + } + } + } else { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + } + } else if(DirectDrawState.flipping == double_buffer) { + if (!currprefs.gfx_afullscreen && !currprefs.gfx_avsync) { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); + } else { + ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + idletime += read_processor_time() - start; + } + } else { + return 1; + } + if(SUCCEEDED(ddrval)) { + result = 1; + } else { + if (ddrval == DDERR_SURFACELOST) { + static int recurse; + IDirectDrawSurface7_Restore (DirectDrawState.primary.surface); + if (!recurse) { + recurse++; + DirectDraw_Flip (wait); + recurse--; + } + } else { + write_log ("FLIP: DirectDrawSurface_Flip() failed with %s\n", DXError (ddrval)); + } + } + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_Blt(surface_type_e dsttype, LPRECT dstrect, + surface_type_e srctype, LPRECT srcrect, + DWORD flags, LPDDBLTFX fx) +{ + LPDIRECTDRAWSURFACE7 lpDDS4_dst, lpDDS4_src; + + if(dsttype == primary_surface) { + if(DirectDrawState.isoverlay) + lpDDS4_dst = DirectDrawState.overlay.surface; + else + lpDDS4_dst = DirectDrawState.primary.surface; + } else if(dsttype == secondary_surface) { + lpDDS4_dst = DirectDrawState.secondary.surface; + } else if(dsttype == tertiary_surface) { + lpDDS4_dst = DirectDrawState.tertiary.surface; + } else if(dsttype == temporary_surface) { + lpDDS4_dst = DirectDrawState.temporary.surface; + } else { + lpDDS4_dst = DirectDrawState.overlay.surface; + } + + if(srctype == primary_surface) { + lpDDS4_src = DirectDrawState.primary.surface; + } else if(srctype == secondary_surface) { + lpDDS4_src = DirectDrawState.secondary.surface; + } else if(srctype == tertiary_surface) { + lpDDS4_src = DirectDrawState.tertiary.surface; + } else if(srctype == temporary_surface) { + lpDDS4_src = DirectDrawState.temporary.surface; + } else if(srctype == overlay_surface) { + lpDDS4_src = DirectDrawState.overlay.surface; + } else { + lpDDS4_src = NULL; /* For using BltStub to do rect-fills */ + } + return DirectDraw_BltStub(lpDDS4_dst, dstrect, lpDDS4_src, srcrect, flags, fx); +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_WaitForVerticalBlank(DWORD flags) +{ + HRESULT result; + result = IDirectDraw7_WaitForVerticalBlank(DirectDrawState.directdraw.dd, flags, NULL); + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_EnumDisplayModes(DWORD flags, LPDDENUMMODESCALLBACK2 callback) +{ + HRESULT result; + result = IDirectDraw7_EnumDisplayModes(DirectDrawState.directdraw.dd, flags, NULL, NULL, callback); + return result; +} + +HRESULT DirectDraw_EnumDisplays(LPDDENUMCALLBACKEX callback ) +{ + HRESULT result; + result = DirectDrawEnumerateEx (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_FlipToGDISurface(void) +{ + HRESULT result = DDERR_GENERIC; + if(DirectDrawState.initialized) { + result = IDirectDraw7_FlipToGDISurface(DirectDrawState.directdraw.dd); + } + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_GetDC(HDC *hdc, surface_type_e surface) +{ + HRESULT result = ~DD_OK; + if(surface == primary_surface) + result = IDirectDrawSurface7_GetDC (DirectDrawState.primary.surface, hdc); + else if (surface == overlay_surface) + result = IDirectDrawSurface7_GetDC (DirectDrawState.overlay.surface, hdc); + else if (surface == secondary_surface) + result = IDirectDrawSurface7_GetDC (DirectDrawState.secondary.surface, hdc); + return result; +} + +/* + * FUNCTION: + * + * PURPOSE: + * + * PARAMETERS: + * + * RETURNS: + * + * NOTES: + * + * HISTORY: + * 1999.08.02 Brian King Creation + * + */ +HRESULT DirectDraw_ReleaseDC (HDC hdc, surface_type_e surface) +{ + HRESULT result; + if (surface == primary_surface) + result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface, hdc); + else if (surface == overlay_surface) + result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.overlay.surface, hdc); + else + result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.secondary.surface, hdc); + return result; +} + +extern int display_change_requested; + +HRESULT DirectDraw_UpdateOverlay(RECT sr, RECT dr) +{ + HRESULT result = DD_OK; + + if (DirectDrawState.isoverlay && DirectDrawState.overlay.surface) { + if ((drivercaps.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && drivercaps.dwAlignBoundarySrc) + sr.left = (sr.left + drivercaps.dwAlignBoundarySrc / 2) & ~(drivercaps.dwAlignBoundarySrc - 1); + if ((drivercaps.dwCaps & DDCAPS_ALIGNSIZESRC) && drivercaps.dwAlignSizeSrc) + sr.right = sr.left + (sr.right - sr.left + drivercaps.dwAlignSizeSrc / 2) & ~(drivercaps.dwAlignSizeSrc - 1); + if ((drivercaps.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && drivercaps.dwAlignBoundaryDest) + dr.left = (dr.left + drivercaps.dwAlignBoundaryDest / 2) & ~(drivercaps.dwAlignBoundaryDest - 1); + if ((drivercaps.dwCaps & DDCAPS_ALIGNSIZEDEST) && drivercaps.dwAlignSizeDest) + dr.right = dr.left + (dr.right - dr.left) & ~(drivercaps.dwAlignSizeDest - 1); + result = IDirectDrawSurface7_UpdateOverlay(DirectDrawState.overlay.surface, &sr, DirectDrawState.primary.surface, &dr, overlayflags, &overlayfx); + + } + if (FAILED(result)) { + if (result == DDERR_SURFACELOST) + display_change_requested++; + write_log ("UpdateOverlay failed %s\n", DXError (result)); + } + return DD_OK; +} + +char *outGUID (GUID *guid) +{ + static char gb[64]; + if (guid == NULL) + return "NULL"; + sprintf(gb, "%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", + guid->Data1, guid->Data2, guid->Data3, + guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], + guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + return gb; +} + +int DirectDraw_GetPrimaryPixelFormat (LPDDPIXELFORMAT ddpf) +{ + surface_type_e surface_type; + HRESULT ddrval; + + surface_type = DirectDraw_GetLockableType (); + ddpf->dwSize = sizeof (DDPIXELFORMAT); + if (surface_type == overlay_surface) + ddrval = IDirectDrawSurface7_GetPixelFormat (DirectDrawState.overlay.surface, ddpf); + else + ddrval = IDirectDrawSurface7_GetPixelFormat (DirectDrawState.primary.surface, ddpf); + if (FAILED(ddrval)) { + write_log ("GetPixelFormat failed\n%s\n", DXError (ddrval)); + return 0; + } + return 1; +} diff --git a/od-win32/dxwrap.c b/od-win32/dxwrap.c index 6ec5523a..f203a4bd 100755 --- a/od-win32/dxwrap.c +++ b/od-win32/dxwrap.c @@ -1,1381 +1,339 @@ -/* - * UAE - The Ultimate Amiga Emulator - * - * Win32 DirectX Wrappers, to simplify (?) my life. - * - * Copyright 1999 Brian King, under GNU Public License - * - */ #include "sysconfig.h" -#include -#include -#include -#include -#include - -#include -#include -#include -#include - #include "sysdeps.h" #include "options.h" -#include "custom.h" -#include "memory.h" -#include "newcpu.h" -#include "picasso96.h" + #include "dxwrap.h" -#include "win32.h" #include "win32gfx.h" -#include "machdep/rpt.h" - -static BOOL bColourKeyAvailable = FALSE; -static BOOL bOverlayAvailable = FALSE; -static DDCAPS_DX7 drivercaps, helcaps; -static DWORD overlayflags; -static DDOVERLAYFX overlayfx; -extern COLORREF g_dwBackgroundColor; -static int flipinterval_supported; - -#define dxwrite_log - -static HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surface) -{ - HRESULT hr2, hr; - DDSURFACEDESC2 surfacedesc; - - hr = IDirectDrawSurface7_Restore (surface); - if (SUCCEEDED(hr)) { - DDBLTFX bltfx; - memset (&bltfx, 0, sizeof (bltfx)); - bltfx.dwSize = sizeof (bltfx); - hr2 = IDirectDrawSurface7_Blt (surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx); - if (FAILED(hr2)) { - static int crap = 0; - if (hr2 == DDERR_SURFACELOST) { - if (crap) - return hr; - crap = 1; - write_log ("Restore succeeded but following Blt failed with lost surface. Display driver bug?\n"); - return hr; - } - write_log ("Surface clear failed: %s\n", DXError (hr2)); - } - surfacedesc.dwSize = sizeof surfacedesc; - hr2 = IDirectDrawSurface7_Lock(surface, NULL, &surfacedesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - if (SUCCEEDED(hr2)) { - write_log ("Surface Pointer: %p\n", surfacedesc.lpSurface); - IDirectDrawSurface7_Unlock(surface, NULL); - } - } - return hr; -} - - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static void clearsurface(int surface) -{ - DDBLTFX ddbltfx; - memset(&ddbltfx, 0, sizeof(ddbltfx)); - ddbltfx.dwFillColor = 0; - ddbltfx.dwSize = sizeof(ddbltfx); - DirectDraw_Blt(surface, NULL, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); -} - -void DirectDraw_ClearSurfaces(void) -{ - clearsurface(secondary_surface); - if(DirectDrawState.isoverlay) - clearsurface(overlay_surface); -} - -/* - * FUNCTION:ShowDDCaps - * - * PURPOSE:print out the DirectDraw Capabilities - * - * PARAMETERS: - * caps - DDCAPS_DX7 structure - * hw - flag indicating if this 'caps' is for real hardware or the HEL - * - * RETURNS: none - * - * NOTES:none - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static void ShowDDCaps( DDCAPS_DX7 caps, int hw ) -{ - static int shown = 0; - static BOOL reset_shown = FALSE; - if( currprefs.win32_logfile && shown >= 4 && !reset_shown) - { - shown = 0; - reset_shown = TRUE; - } - - if( shown < 2) - { - dxwrite_log ( "DirectDraw Capabilities for %s:\n", hw ? "Display Driver Hardware" : "Display Driver Emulation Layer" ); - if( caps.dwCaps & DDCAPS_BLT ) - dxwrite_log ( "DDCAPS_BLT - Capable of blitting\n" ); - if( caps.dwCaps & DDCAPS_BLTCOLORFILL ) - dxwrite_log ( "DDCAPS_BLTCOLORFILL - Color filling with blitter\n" ); - if( caps.dwCaps & DDCAPS_BLTSTRETCH ) - dxwrite_log ( "DDCAPS_BLTSTRETCH - Stretch blitting\n" ); - if( caps.dwCaps & DDCAPS_CANBLTSYSMEM ) - dxwrite_log ( "DDCAPS_CANBLTSYSMEM - Blits from system memory\n" ); - if( caps.dwCaps & DDCAPS_CANCLIP ) - dxwrite_log ( "DDCAPS_CANCLIP - Can clip while blitting\n" ); - if( caps.dwCaps & DDCAPS_CANCLIPSTRETCHED ) - dxwrite_log ( "DDCAPS_CANCLIPSTRETCHED - Can clip while stretch-blitting\n" ); - if( caps.dwCaps & DDCAPS_COLORKEY ) - { - dxwrite_log ( "DDCAPS_COLORKEY - Can color-key with blits/overlays\n" ); - bColourKeyAvailable = TRUE; - } - if( caps.dwCaps & DDCAPS_GDI ) - dxwrite_log ( "DDCAPS_GDI - Display h/w shared with GDI\n" ); - if( caps.dwCaps & DDCAPS_NOHARDWARE ) - dxwrite_log ( "DDCAPS_NOHARDWARE - no h/w support!\n" ); - if( caps.dwCaps & DDCAPS_OVERLAY ) - { - dxwrite_log ( "DDCAPS_OVERLAY - support for %d overlay(s)\n", caps.dwMaxVisibleOverlays ); - if( bColourKeyAvailable ) - { - if( caps.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY ) - { - dxwrite_log ( "DDCKEYCAPS_DESTOVERLAY - colour-keyed overlays\n" ); - bOverlayAvailable = TRUE; - } - } - } - if( caps.dwCaps & DDCAPS_OVERLAYFOURCC ) - dxwrite_log ( "DDCAPS_OVERLAYFOURCC - overlay can do color-space conversions\n" ); - if( caps.dwCaps & DDCAPS_OVERLAYSTRETCH ) - dxwrite_log ( "DDCAPS_OVERLAYSTRETCH - overlay can stretch with min=%d/max=%d\n", caps.dwMinOverlayStretch, caps.dwMaxOverlayStretch ); - if( caps.dwCaps & DDCAPS_VBI ) - dxwrite_log ( "DDCAPS_VBI - h/w can generate a vertical-blanking interrupt\n" ); - if( caps.dwCaps2 & DDCAPS2_CERTIFIED ) - dxwrite_log ( "DDCAPS2_CERTIFIED - certified driver\n" ); - if( caps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED ) - dxwrite_log ( "DDCAPS2_CANRENDERWINDOWED - GDI windows can be seen when in full-screen\n" ); - if( caps.dwCaps2 & DDCAPS2_NOPAGELOCKREQUIRED ) - dxwrite_log ( "DDCAPS2_NOPAGELOCKREQUIRED - no page locking needed for DMA blits\n" ); - if( caps.dwCaps2 & DDCAPS2_FLIPNOVSYNC ) - dxwrite_log ( "DDCAPS2_FLIPNOVSYNC - can pass DDFLIP_NOVSYNC to Flip calls\n" ); - if( caps.dwCaps2 & DDCAPS2_FLIPINTERVAL ) { - dxwrite_log ( "DDCAPS2_FLIPINTERVAL - can pass DDFLIP_INTERVALx to Flip calls\n" ); - flipinterval_supported = 1; - } - - dxwrite_log ( "Video memory: %d/%d\n", caps.dwVidMemFree, caps.dwVidMemTotal ); - } - shown++; -} -const char *DXError (HRESULT ddrval) -{ - static char dderr[1000]; - sprintf(dderr, "%08.8X S=%d F=%04.4X C=%04.4X (%d) (%s)", - ddrval, (ddrval & 0x80000000) ? 1 : 0, - HRESULT_FACILITY(ddrval), - HRESULT_CODE(ddrval), - HRESULT_CODE(ddrval), - DXGetErrorDescription9 (ddrval)); - return dderr; -} +#include -struct DirectDrawSurfaceMapper DirectDrawState; -static int lockcnt = 0; +struct ddstuff dxdata; +static int flipinterval_supported = 1; -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static int LockStub( surface_type_e type ) +HRESULT DirectDraw_GetDisplayMode (void) { - int result = 0; HRESULT ddrval; - LPDIRECTDRAWSURFACE7 surface; - LPDDSURFACEDESC2 surfacedesc; - - switch( type ) - { - case primary_surface: - surface = DirectDrawState.primary.surface; - surfacedesc = &DirectDrawState.primary.desc; - break; - case secondary_surface: - surface = DirectDrawState.secondary.surface; - surfacedesc = &DirectDrawState.secondary.desc; - break; - case tertiary_surface: - surface = DirectDrawState.tertiary.surface; - surfacedesc = &DirectDrawState.tertiary.desc; - break; - case temporary_surface: - surface = DirectDrawState.temporary.surface; - surfacedesc = &DirectDrawState.temporary.desc; - break; - case overlay_surface: - surface = DirectDrawState.overlay.surface; - surfacedesc = &DirectDrawState.overlay.desc; - break; - } - - if(lockcnt) - { -#ifdef _DEBUG - //DebugBreak(); -#endif - return 1; - } - - if(type == secondary_surface && DirectDrawState.flipping != single_buffer) - { - IDirectDrawSurface7_Restore(DirectDrawState.primary.surface); - } - - while (FAILED(ddrval = IDirectDrawSurface7_Lock(surface, NULL, surfacedesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) - { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (surface); - if (FAILED(ddrval)) - break; - } - else if (ddrval != DDERR_SURFACEBUSY) - { - write_log ("lpDDS->Lock() failed - %s\n", DXError (ddrval)); - break; - } - } - if(SUCCEEDED(ddrval)) { - static int warned = 10; - DWORD_PTR pixels = (DWORD_PTR)(surfacedesc->lpSurface); - if (warned > 0 && (pixels & 7)) { - write_log ("bogus surface pointer %x!\n", pixels); - warned--; - } - lockcnt++; - result = 1; - } - return result; -} - -/* For a given surface-type, update our DirectDrawState structure */ -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -int DirectDraw_SurfaceLock(surface_type_e surface_type) -{ - int result = 0; - - if (surface_type == lockable_surface) - surface_type = DirectDraw_GetLockableType(); - - switch(surface_type) - { - case primary_surface: - DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); - result = LockStub(surface_type); - break; - case secondary_surface: - DirectDrawState.secondary.desc.dwSize = sizeof(DDSURFACEDESC2); - result = LockStub(surface_type); - break; - case tertiary_surface: - DirectDrawState.tertiary.desc.dwSize = sizeof(DDSURFACEDESC2); - result = LockStub(surface_type); - break; - case temporary_surface: - DirectDrawState.temporary.desc.dwSize = sizeof(DDSURFACEDESC2); - result = LockStub(surface_type); - break; - case overlay_surface: - DirectDrawState.overlay.desc.dwSize = sizeof(DDSURFACEDESC2); - result = LockStub(surface_type); - case lockable_surface: - case invalid_surface: - default: - - break; - } - DirectDrawState.locked = result; - - return result; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -char *DirectDraw_GetSurfacePointer(void) -{ - char *pixels = NULL; - - /* Make sure that somebody has done a lock before returning the lpSurface member */ - if(lockcnt) - pixels = DirectDrawState.lockable.lpdesc->lpSurface; - return pixels; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -LONG DirectDraw_GetSurfacePitch(void) -{ - LONG pitch = 0; - - pitch = DirectDrawState.lockable.lpdesc->lPitch; - return pitch; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_GetPixelFormatFlags(void) -{ - DWORD flags = 0; - flags = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwFlags; - return flags; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_GetSurfaceFlags(void) -{ - DWORD flags = 0; - flags = DirectDrawState.lockable.lpdesc->dwFlags; - return flags; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_GetSurfaceBitCount(void) -{ - DWORD bits = 0; - //?????JGI begin: - if(DirectDrawState.lockable.lpdesc) - bits = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRGBBitCount; - else - bits = DirectDrawState.current.desc.ddpfPixelFormat.dwRGBBitCount; - //?????JGI end. - return bits; -} - -/* - * FUNCTION:DirectDraw_GetPrimaryBitCount - * - * PURPOSE:Return the bit-depth of the primary surface - * - * PARAMETERS: none - * - * RETURNS: bit-depth - * - * NOTES: - * - * HISTORY: - * 2001.08.25 Brian King Creation - * - */ -DWORD DirectDraw_GetPrimaryBitCount(void) -{ - DWORD bits = 0; - memset(&DirectDrawState.primary.desc,0,sizeof(DirectDrawState.primary.desc)); - DirectDrawState.primary.desc.dwSize = sizeof(DirectDrawState.primary.desc); - IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &DirectDrawState.primary.desc); - bits = DirectDrawState.primary.desc.ddpfPixelFormat.dwRGBBitCount; - return bits; + dxdata.native.dwSize = sizeof (DDSURFACEDESC2); + ddrval = IDirectDraw7_GetDisplayMode (dxdata.maindd, &dxdata.native); + if (FAILED (ddrval)) + write_log ("IDirectDraw7_GetDisplayMode: %s\n", DXError (ddrval)); + return ddrval; } -void DirectDraw_GetPrimaryWidthHeight(int *w, int *h) -{ - memset(&DirectDrawState.primary.desc,0,sizeof(DirectDrawState.primary.desc)); - DirectDrawState.primary.desc.dwSize = sizeof(DirectDrawState.primary.desc); - IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &DirectDrawState.primary.desc); - *w = DirectDrawState.primary.desc.dwWidth; - *h = DirectDrawState.primary.desc.dwHeight; -} +#define releaser(x, y) if (x) { y (x); x = NULL; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_GetPixelFormatBitMask(DirectDraw_Mask_e mask) +static void freemainsurface (void) { - DWORD result = 0; - switch(mask) - { - case red_mask: - result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRBitMask; - break; - case green_mask: - result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwGBitMask; - break; - case blue_mask: - result = DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwBBitMask; - break; + if (dxdata.dclip) { + DirectDraw_SetClipper (NULL); + releaser (dxdata.dclip, IDirectDrawClipper_Release); } - return result; + releaser (dxdata.flipping[1], IDirectDrawSurface7_Release); + releaser (dxdata.flipping[0], IDirectDrawSurface7_Release); + releaser (dxdata.primary, IDirectDrawSurface7_Release); + releaser (dxdata.secondary, IDirectDrawSurface7_Release); + dxdata.backbuffers = 0; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -surface_type_e DirectDraw_GetLockableType(void) +void DirectDraw_Release (void) { - return DirectDrawState.surface_type; + if (!dxdata.ddinit) + return; + dxdata.ddinit = 0; + freemainsurface (); + if (dxdata.fsmodeset) + IDirectDraw7_RestoreDisplayMode(dxdata.maindd); + dxdata.fsmodeset = 0; + IDirectDraw7_SetCooperativeLevel(dxdata.maindd, dxdata.hwnd, DDSCL_NORMAL); + releaser (dxdata.dclip, IDirectDrawClipper_Release); + releaser (dxdata.maindd, IDirectDraw_Release); + memset (&dxdata, 0, sizeof (dxdata)); } -/* - * FUNCTION:DirectDraw_IsLocked - * - * PURPOSE:Return whether we're currently locked or unlocked - * - * PARAMETERS: none - * - * RETURNS: TRUE if already locked, FALSE otherwise - * - * NOTES:Used by DX_Blit to possibly unlock during Blit operation - * - * HISTORY: - * 2000.04.30 Brian King Creation - * - */ -BOOL DirectDraw_IsLocked(void) +int DirectDraw_Start (GUID *guid) { - return DirectDrawState.locked ? TRUE : FALSE; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static surface_type_e try_surface_locks(int want_fullscreen) -{ - surface_type_e result = invalid_surface; - - if(DirectDrawState.isoverlay && DirectDraw_SurfaceLock(overlay_surface)) - { - result = overlay_surface; - write_log ("try_surface_locks() returning overlay\n"); - } - else if(want_fullscreen && WIN32GFX_IsPicassoScreen()) - { - if(DirectDraw_SurfaceLock(primary_surface)) - { - result = primary_surface; - write_log ("try_surface_locks() returning primary\n"); - } - else if(DirectDraw_SurfaceLock(secondary_surface)) - { - result = secondary_surface; - write_log ("try_surface_locks() returning secondary\n"); - } - } - else - { - if(DirectDraw_SurfaceLock(secondary_surface)) - { - result = secondary_surface; - write_log ("try_surface_locks() returning secondary\n"); - } - } - - return result; -} + HRESULT ddrval; -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES:Named this way for historical reasons - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -void ddraw_unlockscr(void) -{ - if(lockcnt > 0) { - lockcnt--; - IDirectDrawSurface7_Unlock(DirectDrawState.lockable.surface, - DirectDrawState.lockable.lpdesc->lpSurface); - DirectDrawState.locked = FALSE; + if (dxdata.ddinit) { + if (guid == NULL && dxdata.ddzeroguid) + return -1; + if (guid && !memcmp (guid, &dxdata.ddguid, sizeof (GUID))) + return -1; + DirectDraw_Release (); } -} -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -int DirectDraw_Start(GUID *guid) -{ - HRESULT ddrval; - /* Prepare our DirectDrawState structure */ - ZeroMemory(&DirectDrawState, sizeof(DirectDrawState)); - ZeroMemory(&drivercaps, sizeof(drivercaps)); - ZeroMemory(&helcaps, sizeof(helcaps)); - drivercaps.dwSize = sizeof(drivercaps); - helcaps.dwSize = sizeof(helcaps); - - ddrval = DirectDrawCreate(guid, &DirectDrawState.directdraw.ddx, NULL); + ddrval = DirectDrawCreate(guid, &dxdata.olddd, NULL); if (FAILED(ddrval)) { if (guid != NULL) return 0; goto oops; } - - DirectDrawState.initialized = TRUE; - - ddrval = IDirectDraw_QueryInterface(DirectDrawState.directdraw.ddx, - &IID_IDirectDraw7, (LPVOID *)&DirectDrawState.directdraw.dd); + ddrval = IDirectDraw_QueryInterface(dxdata.olddd, &IID_IDirectDraw7, (LPVOID*)&dxdata.maindd); if(FAILED(ddrval)) { gui_message("start_ddraw(): DirectX 7 or newer required"); DirectDraw_Release(); return 0; } - DirectDraw_GetCaps(&drivercaps, &helcaps); - ShowDDCaps(drivercaps, 1); - ShowDDCaps(helcaps, 0); - if (SUCCEEDED(DirectDraw_GetDisplayMode ())) + if (SUCCEEDED(DirectDraw_GetDisplayMode ())) { + dxdata.ddinit = 1; + dxdata.ddzeroguid = 1; + if (guid) { + dxdata.ddzeroguid = 0; + memcpy (&dxdata.ddguid, guid, sizeof (GUID)); + } return 1; - if (guid != NULL) { - DirectDraw_Release (); - return 0; } - oops: - gui_message ("start_ddraw(): DirectDraw initialization failed with %s\n", DXError (ddrval)); + write_log ("DirectDraw_Start: %s\n", DXError (ddrval)); DirectDraw_Release(); return 0; } -#define releaser(x,y) if( x ) { y( x ); x = NULL; } - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -void DirectDraw_Release(void) -{ - releaser(DirectDrawState.lpDDC, IDirectDrawClipper_Release); - releaser(DirectDrawState.lpDDP, IDirectDrawPalette_Release); - - if (DirectDrawState.directdraw.dd && DirectDrawState.modeset) { - IDirectDraw7_RestoreDisplayMode(DirectDrawState.directdraw.dd); - IDirectDraw7_SetCooperativeLevel(DirectDrawState.directdraw.dd, hAmigaWnd, DDSCL_NORMAL); - } - DirectDrawState.modeset = 0; - - releaser(DirectDrawState.overlay.surface, IDirectDrawSurface7_Release); - releaser(DirectDrawState.primary.surface, IDirectDrawSurface7_Release); - - if(DirectDrawState.flipping == single_buffer) - releaser(DirectDrawState.secondary.surface, IDirectDrawSurface7_Release); - - releaser(DirectDrawState.directdraw.dd, IDirectDraw_Release); - - DirectDrawState.lockable.lpdesc = NULL; - DirectDrawState.lockable.lpdesc = NULL; - DirectDrawState.lockable.surface = NULL; - DirectDrawState.lockable.surface = NULL; - - DirectDrawState.surface_type = invalid_surface; - DirectDrawState.initialized = FALSE; - DirectDrawState.isoverlay = FALSE; -} - -/* - * FUNCTION:DirectDraw_SetCooperativeLevel - * - * PURPOSE:Wrapper for setting the cooperative level (fullscreen or normal) - * - * PARAMETERS: - * window Window to set the cooperative level for - * want_fullscreen fullscreen mode flag - * - * RETURNS: result of underlying DirectDraw call - * - * NOTES: Updates the .fullscreen and .window members. - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_SetCooperativeLevel(HWND window, int want_fullscreen) +HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surf) { HRESULT ddrval; - - ddrval = IDirectDraw7_SetCooperativeLevel(DirectDrawState.directdraw.dd, - window, want_fullscreen ? - DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); - if(SUCCEEDED(ddrval)) { - DirectDrawState.fullscreen = want_fullscreen; - DirectDrawState.window = window; - } + + if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) + surf = dxdata.primary; + ddrval = IDirectDrawSurface7_Restore (surf); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_Restore: %s\n", DXError (ddrval)); return ddrval; } -/* - * FUNCTION:DirectDraw_GetCooperativeLevel - * - * PURPOSE:Wrapper for setting the cooperative level (fullscreen or normal) - * - * PARAMETERS: - * window Window to set the cooperative level for - * want_fullscreen fullscreen mode flag - * - * RETURNS: result of underlying DirectDraw call - * - * NOTES: Updates the .fullscreen and .window members. - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -BOOL DirectDraw_GetCooperativeLevel(HWND *window, int *fullscreen) +void clearsurface (LPDIRECTDRAWSURFACE7 surf) { - BOOL result = FALSE; + HRESULT ddrval; + DDBLTFX ddbltfx; - if(DirectDrawState.initialized) { - *fullscreen = DirectDrawState.fullscreen; - *window = DirectDrawState.window; - result = TRUE; + if (surf == NULL) + return; + memset(&ddbltfx, 0, sizeof (ddbltfx)); + ddbltfx.dwFillColor = 0; + ddbltfx.dwSize = sizeof (ddbltfx); + while (FAILED(ddrval = IDirectDrawSurface7_Blt (surf, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (dxdata.primary); + if (FAILED (ddrval)) + break; + } else if (ddrval != DDERR_SURFACEBUSY) { + break; + } } - return result; -} -/* - * FUNCTION:DirectDraw_SetDisplayMode - * - * PURPOSE:Change the display-mode to width x height pixels, with a given - * vertical refresh-rate. - * - * PARAMETERS: - * width - width of display in pixels - * height - height of display in pixels - * freq - vertical refresh-rate in Hz - * - * RETURNS: - * ddrval - HRESULT indicating success (DD_OK) or failure - * - * NOTES:The freq parameter is only obeyed on when we're using DirectX 6 - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_SetDisplayMode(int width, int height, int bits, int freq) -{ - HRESULT ddrval; - - ddrval = IDirectDraw7_SetDisplayMode(DirectDrawState.directdraw.dd, - width, height, bits, freq, 0); - DirectDrawState.modeset = 1; - return ddrval; } -/* - * FUNCTION:DirectDraw_GetDisplayMode - * - * PURPOSE:Get the display-mode characteristics. - * - * PARAMETERS: none - * - * RETURNS: - * ddrval - HRESULT indicating success (DD_OK) or failure - * - * NOTES:none - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_GetDisplayMode(void) +int locksurface (LPDIRECTDRAWSURFACE7 surf, LPDDSURFACEDESC2 desc) { HRESULT ddrval; - - /* We fill in the current.desc in all cases */ - DirectDrawState.current.desc.dwSize = sizeof(DDSURFACEDESC2); - ddrval = IDirectDraw7_GetDisplayMode(DirectDrawState.directdraw.dd, - &DirectDrawState.current.desc); - return ddrval; + desc->dwSize = sizeof (*desc); + while (FAILED(ddrval = IDirectDrawSurface7_Lock (surf, NULL, desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (surf); + if (FAILED(ddrval)) + return 0; + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log ("locksurface: %s\n", DXError (ddrval)); + return 0; + } + } + return 1; } - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_GetCaps(DDCAPS_DX7 *driver_caps, DDCAPS_DX7 *hel_caps) +void unlocksurface (LPDIRECTDRAWSURFACE7 surf) { HRESULT ddrval; - ddrval = IDirectDraw7_GetCaps(DirectDrawState.directdraw.dd, - driver_caps, hel_caps); - return ddrval; + ddrval = IDirectDrawSurface7_Unlock (surf, NULL); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_Unlock: %s\n", DXError (ddrval)); } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_CreateClipper(void) +LPDIRECTDRAWSURFACE7 allocsurface (int width, int height) { HRESULT ddrval; - ddrval = IDirectDraw7_CreateClipper(DirectDrawState.directdraw.dd, - 0, &DirectDrawState.lpDDC, NULL); - return ddrval; + DDSURFACEDESC2 desc = { 0 }; + LPDIRECTDRAWSURFACE7 surf; + + desc.dwSize = sizeof (desc); + desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; + desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + desc.dwWidth = width; + desc.dwHeight = height; + memcpy (&desc.ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &surf, NULL); + if (FAILED (ddrval)) { + write_log ("IDirectDraw7_CreateSurface: %s\n", DXError (ddrval)); + } else { + clearsurface (surf); + } + return surf; } - -static DWORD ConvertGDIColor(COLORREF dwGDIColor) +void freesurface (LPDIRECTDRAWSURFACE7 surf) { - COLORREF rgbT; - HDC hdc; - DWORD dw = CLR_INVALID; - DDSURFACEDESC2 ddsd,pdds; - HRESULT hr; - - memset(&pdds,0,sizeof(pdds)); - pdds.dwSize = sizeof(pdds); - - IDirectDrawSurface7_GetSurfaceDesc(DirectDrawState.primary.surface, &pdds); - - // Use GDI SetPixel to color match for us - if(dwGDIColor != CLR_INVALID && SUCCEEDED(IDirectDrawSurface7_GetDC(DirectDrawState.primary.surface, &hdc))) { - rgbT = GetPixel(hdc, 0, 0); // Save current pixel value - SetPixel(hdc, 0, 0, dwGDIColor); // Set our value - IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface,hdc); - } - - // Now lock the surface so we can read back the converted color - ddsd.dwSize = sizeof(ddsd); - hr = IDirectDrawSurface7_Lock(DirectDrawState.primary.surface, NULL, &ddsd, DDLOCK_WAIT, NULL ); - if(SUCCEEDED(hr)) { - dw = *(DWORD *) ddsd.lpSurface; - if(ddsd.ddpfPixelFormat.dwRGBBitCount < 32) // Mask it to bpp - dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; - IDirectDrawSurface7_Unlock(DirectDrawState.primary.surface,NULL); - } - - // Now put the color that was there back. - if(dwGDIColor != CLR_INVALID && SUCCEEDED(IDirectDrawSurface7_GetDC(DirectDrawState.primary.surface,&hdc))) { - SetPixel(hdc, 0, 0, rgbT); - IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface,hdc); - } - - return dw; + if (surf) + IDirectDrawSurface7_Release (surf); } - -HRESULT DirectDraw_CreateOverlaySurface(int width, int height, int bits, int type) +void DirectDraw_FreeMainSurface (void) { - DDSURFACEDESC2 ddsd; - DDPIXELFORMAT ddpfOverlayFormat; - HRESULT ddrval = DDERR_UNSUPPORTED; - DWORD dwDDSColor; - DWORD flags = DDPF_RGB; - - ZeroMemory(&ddpfOverlayFormat, sizeof(ddpfOverlayFormat)); - ddpfOverlayFormat.dwSize = sizeof(ddpfOverlayFormat); - ZeroMemory(&ddsd, sizeof(ddsd)); - - if (bOverlayAvailable) { - write_log ( "CreateOverlaySurface being called with %d-bits!\n", bits ); - if(bits == 16) { - // Set the overlay format to 16 bit RGB 5:6:5 - ddpfOverlayFormat.dwFlags = flags; - ddpfOverlayFormat.dwRGBBitCount = 16; - ddpfOverlayFormat.dwRBitMask = 0xF800; - ddpfOverlayFormat.dwGBitMask = 0x07E0; - ddpfOverlayFormat.dwBBitMask = 0x001F; - } else if(bits == 32) { - // Set the overlay format to 32 bit ARGB 8:8:8:8 - ddpfOverlayFormat.dwFlags = flags; - ddpfOverlayFormat.dwRGBBitCount = 32; - ddpfOverlayFormat.dwRBitMask = 0x00FF0000; - ddpfOverlayFormat.dwGBitMask = 0x0000FF00; - ddpfOverlayFormat.dwBBitMask = 0x000000FF; - } else if(bits == 8) { - // Set the overlay format to 8 bit palette - ddpfOverlayFormat.dwFlags = flags | DDPF_PALETTEINDEXED8; - ddpfOverlayFormat.dwRGBBitCount = 8; - ddpfOverlayFormat.dwRBitMask = 0x00000000; - ddpfOverlayFormat.dwGBitMask = 0x00000000; - ddpfOverlayFormat.dwBBitMask = 0x00000000; - } else { - // We don't handle this case... - return DDERR_INVALIDPIXELFORMAT; - } - - // Setup the overlay surface's attributes in the surface descriptor - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; - ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; - ddsd.dwWidth = width; - ddsd.dwHeight = height; - ddsd.ddpfPixelFormat = ddpfOverlayFormat; - - ZeroMemory(&overlayfx, sizeof(overlayfx)); - overlayfx.dwSize = sizeof(overlayfx); - overlayflags = DDOVER_SHOW | DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE; - - dwDDSColor = ConvertGDIColor(g_dwBackgroundColor); - overlayfx.dckDestColorkey.dwColorSpaceLowValue = dwDDSColor; - overlayfx.dckDestColorkey.dwColorSpaceHighValue = dwDDSColor; - - // Attempt to create the surface with theses settings - ddrval = IDirectDraw7_CreateSurface (DirectDrawState.directdraw.dd, &ddsd, &DirectDrawState.overlay.surface, NULL); - if(SUCCEEDED(ddrval)) { - DirectDrawState.isoverlay = 1; - } else { - DirectDrawState.isoverlay = 0; - } - } else { - write_log ( "CreateOverlaySurface being called, but no overlay support with this card...!\n" ); - } - return ddrval; + freemainsurface (); } - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_CreateSurface(int width, int height) +HRESULT DirectDraw_CreateMainSurface (int width, int height) { HRESULT ddrval; - DWORD xtraflag = 0; - - DirectDrawState.flipping = single_buffer; - - if (DirectDrawState.fullscreen) { // Create a flipping pair! - ZeroMemory (&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); - DirectDrawState.primary.desc.dwSize = sizeof (DDSURFACEDESC2); - DirectDrawState.primary.desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; - DirectDrawState.primary.desc.dwBackBufferCount = 2; - ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, - &DirectDrawState.primary.desc, &DirectDrawState.primary.surface, NULL); - if (FAILED(ddrval)) { - // Create a non-flipping pair, since the flipping pair creation failed... - ZeroMemory (&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); - DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); - DirectDrawState.primary.desc.dwFlags = DDSD_CAPS; - DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, - &DirectDrawState.primary.desc, - &DirectDrawState.primary.surface, - NULL); - } else { - DirectDrawState.flipping = triple_buffer; + DDSURFACEDESC2 desc = { 0 }; + LPDIRECTDRAWSURFACE7 surf; + + desc.dwSize = sizeof (desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + if (dxdata.fsmodeset) { + DWORD oldcaps = desc.ddsCaps.dwCaps; + DWORD oldflags = desc.dwFlags; + desc.dwFlags |= DDSD_BACKBUFFERCOUNT; + desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; + desc.dwBackBufferCount = 1; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + if (FAILED (ddrval)) { + desc.dwBackBufferCount = 1; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); } - clearsurface (primary_surface); - } else { - // We're not full-screen, so you cannot create a flipping pair... - ZeroMemory(&DirectDrawState.primary.desc, sizeof(DDSURFACEDESC2)); - DirectDrawState.primary.desc.dwSize = sizeof(DDSURFACEDESC2); - DirectDrawState.primary.desc.dwFlags = DDSD_CAPS; - DirectDrawState.primary.desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, - &DirectDrawState.primary.desc, &DirectDrawState.primary.surface, NULL); - } - - if(FAILED(ddrval)) { - goto errout; - } else { - write_log ( "DDRAW: Primary %ssurface created in video-memory\n", - DirectDrawState.flipping != single_buffer ? "flipping " : ""); - } - - // Check if we can access the back-buffer of our flipping-pair (if present) - if(DirectDrawState.flipping != single_buffer) { - DDSCAPS2 ddSCaps; - ZeroMemory(&ddSCaps, sizeof(ddSCaps)); - ddSCaps.dwCaps = DDSCAPS_BACKBUFFER; - - ddrval = IDirectDrawSurface7_GetAttachedSurface(DirectDrawState.primary.surface, &ddSCaps, &DirectDrawState.secondary.surface); - if(SUCCEEDED(ddrval)) { - /* get third buffer */ - ZeroMemory(&ddSCaps, sizeof(ddSCaps)); - ddSCaps.dwCaps = DDSCAPS_FLIP; - - ddrval = IDirectDrawSurface7_GetAttachedSurface(DirectDrawState.secondary.surface, &ddSCaps, &DirectDrawState.tertiary.surface); - if(SUCCEEDED(ddrval)) { - clearsurface (tertiary_surface); - } else { - DirectDrawState.flipping = single_buffer; + if (SUCCEEDED (ddrval)) { + DDSCAPS2 ddscaps; + memset (&ddscaps, 0, sizeof (ddscaps)); + ddscaps.dwCaps = DDSCAPS_BACKBUFFER; + ddrval = IDirectDrawSurface7_GetAttachedSurface (dxdata.primary, &ddscaps, &dxdata.flipping[0]); + if(SUCCEEDED (ddrval) && desc.dwBackBufferCount > 1) { + memset (&ddscaps, 0, sizeof (ddscaps)); + ddscaps.dwCaps = DDSCAPS_FLIP; + ddrval = IDirectDrawSurface7_GetAttachedSurface (dxdata.flipping[0], &ddscaps, &dxdata.flipping[1]); } + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_GetAttachedSurface: %s\n", DXError (ddrval)); } else { - DirectDrawState.flipping = single_buffer; + desc.dwBackBufferCount = 0; + desc.ddsCaps.dwCaps = oldcaps; + desc.dwFlags = oldflags; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); } - } - - // We always want a secondary-buffer when creating our primary-surface. If we're a flipping pair, - // the secondary buffer is already allocated. If we failed to create a flipping pair, or because - // we're not full-screen, then lets create ourselves a back-buffer manually. - if(DirectDrawState.flipping == single_buffer) { - ZeroMemory(&DirectDrawState.secondary.desc, sizeof(DDSURFACEDESC2)); - DirectDrawState.secondary.desc.dwSize = sizeof(DDSURFACEDESC2); - DirectDrawState.secondary.desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - DirectDrawState.secondary.desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | xtraflag; - DirectDrawState.secondary.desc.dwWidth = width; - DirectDrawState.secondary.desc.dwHeight = height; - ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, - &DirectDrawState.secondary.desc, &DirectDrawState.secondary.surface, NULL); - if(FAILED(ddrval)) { - write_log ( "DDRAW:Secondary surface creation attempt #1 failed with %s\n", DXError(ddrval)); - DirectDrawState.secondary.desc.ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY; - DirectDrawState.secondary.desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; - ddrval = IDirectDraw7_CreateSurface(DirectDrawState.directdraw.dd, - &DirectDrawState.secondary.desc, &DirectDrawState.secondary.surface, NULL); - if(SUCCEEDED(ddrval)) - write_log ("DDRAW: Secondary surface created in plain system-memory\n"); - else - goto errout; - } else { - write_log ("DDRAW: Secondary surface created in video-memory\n"); + } else { + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); + } + if (FAILED (ddrval)) { + write_log ("IDirectDraw7_CreateSurface: %s\n", DXError (ddrval)); + return ddrval; + } + if (dxdata.fsmodeset) + clearsurface (dxdata.primary); + dxdata.backbuffers = desc.dwBackBufferCount; + clearsurface (dxdata.flipping[0]); + clearsurface (dxdata.flipping[1]); + ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_GetSurfaceDesc: %s\n", DXError (ddrval)); + surf = allocsurface (width, height); + if (surf) { + dxdata.secondary = surf; + dxdata.swidth = width; + dxdata.sheight = height; + if (locksurface (surf, &desc)) { + dxdata.pitch = desc.lPitch; + unlocksurface (surf); } + } else { + ddrval = DD_FALSE; } - DirectDraw_ClearSurfaces (); -errout: return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -int DirectDraw_DetermineLocking( int wantfull ) +HRESULT DirectDraw_SetDisplayMode(int width, int height, int bits, int freq) { - int result = 0; + HRESULT ddrval; - switch(DirectDrawState.surface_type = try_surface_locks(wantfull)) - { - case invalid_surface: - case lockable_surface: - DirectDrawState.lockable.lpdesc = NULL; - DirectDrawState.lockable.lpdesc = NULL; - DirectDrawState.lockable.surface = NULL; - DirectDrawState.lockable.surface = NULL; - write_log ("set_ddraw: Couldn't lock primary, and no secondary available.\n"); - break; - case primary_surface: - DirectDrawState.lockable.lpdesc = &DirectDrawState.primary.desc; - DirectDrawState.lockable.lpdesc = &DirectDrawState.primary.desc; - DirectDrawState.lockable.surface = DirectDrawState.primary.surface; - DirectDrawState.lockable.surface = DirectDrawState.primary.surface; - result = 1; - break; - case overlay_surface: - DirectDrawState.lockable.lpdesc = &DirectDrawState.overlay.desc; - DirectDrawState.lockable.lpdesc = &DirectDrawState.overlay.desc; - DirectDrawState.lockable.surface = DirectDrawState.overlay.surface; - DirectDrawState.lockable.surface = DirectDrawState.overlay.surface; - result = 1; - break; - case secondary_surface: - DirectDrawState.lockable.lpdesc = &DirectDrawState.secondary.desc; - DirectDrawState.lockable.lpdesc = &DirectDrawState.secondary.desc; - DirectDrawState.lockable.surface = DirectDrawState.secondary.surface; - DirectDrawState.lockable.surface = DirectDrawState.secondary.surface; - result = 1; - break; - case tertiary_surface: - DirectDrawState.lockable.lpdesc = &DirectDrawState.tertiary.desc; - DirectDrawState.lockable.lpdesc = &DirectDrawState.tertiary.desc; - DirectDrawState.lockable.surface = DirectDrawState.tertiary.surface; - DirectDrawState.lockable.surface = DirectDrawState.tertiary.surface; - result = 1; - break; + if (dxdata.fsmodeset && dxdata.width == width && dxdata.height == height && + dxdata.depth == bits && dxdata.freq == freq) + return DD_OK; + ddrval = IDirectDraw7_SetDisplayMode(dxdata.maindd, width, height, bits, freq, 0); + if (FAILED (ddrval)) { + write_log ("IDirectDraw7_SetDisplayMode: %s\n", DXError (ddrval)); + } else { + dxdata.fsmodeset = 1; + dxdata.width = width; + dxdata.height = height; + dxdata.depth = bits; + dxdata.freq = freq; } - - if(DirectDrawState.lockable.surface) - DirectDraw_SurfaceUnlock(); - - return result; + return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_SetClipper(HWND hWnd) +HRESULT DirectDraw_SetCooperativeLevel (HWND window, int fullscreen) { HRESULT ddrval; - - ddrval = IDirectDrawSurface7_SetClipper(DirectDrawState.primary.surface, - hWnd ? DirectDrawState.lpDDC : NULL); - if(hWnd && SUCCEEDED(ddrval)) - ddrval = IDirectDrawClipper_SetHWnd(DirectDrawState.lpDDC, 0, hWnd); + + dxdata.hwnd = window; + ddrval = IDirectDraw7_SetCooperativeLevel(dxdata.maindd, window, fullscreen ? + DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); + if (FAILED (ddrval)) + write_log ("IDirectDraw7_SetCooperativeLevel: %s\n", DXError (ddrval)); return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_GetClipList(LPRGNDATA cliplist, LPDWORD size) +HRESULT DirectDraw_CreateClipper (void) { HRESULT ddrval; - ddrval = IDirectDrawClipper_GetClipList(DirectDrawState.lpDDC, NULL, cliplist, size); - + ddrval = IDirectDraw7_CreateClipper (dxdata.maindd, 0, &dxdata.dclip, NULL); + if (FAILED (ddrval)) + write_log ("IDirectDraw7_CreateClipper: %s\n", DXError (ddrval)); return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -int DirectDraw_GetBytesPerPixel(void) -{ - if(DirectDrawState.lockable.lpdesc) - return (DirectDrawState.lockable.lpdesc->ddpfPixelFormat.dwRGBBitCount + 7) >> 3; - return 0; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_SetPalette(int remove) +HRESULT DirectDraw_SetClipper(HWND hWnd) { HRESULT ddrval; - if (DirectDrawState.primary.surface == NULL) - return DDERR_SURFACELOST; - ddrval = IDirectDrawSurface7_SetPalette (DirectDrawState.primary.surface, - remove ? NULL : DirectDrawState.lpDDP); - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (DirectDrawState.primary.surface); - if (SUCCEEDED(ddrval)) { - ddrval = IDirectDrawSurface7_SetPalette (DirectDrawState.primary.surface, - remove ? NULL : DirectDrawState.lpDDP); - } + + ddrval = IDirectDrawSurface7_SetClipper (dxdata.primary, hWnd ? dxdata.dclip : NULL); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_SetClipper: %s\n", DXError (ddrval)); + if(hWnd && SUCCEEDED(ddrval)) { + ddrval = IDirectDrawClipper_SetHWnd (dxdata.dclip, 0, hWnd); + if (FAILED (ddrval)) + write_log ("IDirectDrawClipper_SetHWnd: %s\n", DXError (ddrval)); } return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_CreatePalette(LPPALETTEENTRY pal) + +char *outGUID (GUID *guid) { - HRESULT ddrval; - ddrval = IDirectDraw_CreatePalette(DirectDrawState.directdraw.dd, - DDPCAPS_8BIT | DDPCAPS_ALLOW256, pal, &DirectDrawState.lpDDP, NULL); - if(SUCCEEDED(ddrval)) - ddrval = DirectDraw_SetPalette(0); - return ddrval; + static char gb[64]; + if (guid == NULL) + return "NULL"; + sprintf(gb, "%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", + guid->Data1, guid->Data2, guid->Data3, + guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], + guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + return gb; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_SetPaletteEntries(int start, int count, PALETTEENTRY *palette) +const char *DXError (HRESULT ddrval) { - HRESULT ddrval = DDERR_NOPALETTEATTACHED; - if(DirectDrawState.lpDDP) - ddrval = IDirectDrawPalette_SetEntries(DirectDrawState.lpDDP, 0, start, count, palette); - return ddrval; + static char dderr[1000]; + sprintf(dderr, "%08.8X S=%d F=%04.4X C=%04.4X (%d) (%s)", + ddrval, (ddrval & 0x80000000) ? 1 : 0, + HRESULT_FACILITY(ddrval), + HRESULT_CODE(ddrval), + HRESULT_CODE(ddrval), + DXGetErrorDescription9 (ddrval)); + return dderr; } -/* Return one of the pixel formats declared in picasso96.h if the surface - * is usable for us, or RGBFB_NONE if it is not usable. */ -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface) { int surface_is = 0; @@ -1439,512 +397,237 @@ RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface) return RGBFB_NONE; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -RGBFTYPE DirectDraw_GetPixelFormat(void) +HRESULT DirectDraw_EnumDisplayModes(DWORD flags, LPDDENUMMODESCALLBACK2 callback) { - RGBFTYPE type; - if(DirectDrawState.lockable.lpdesc) - type = DirectDraw_GetSurfacePixelFormat(DirectDrawState.lockable.lpdesc); - else - type = DirectDraw_GetSurfacePixelFormat(&DirectDrawState.current.desc); - return type; + HRESULT result; + result = IDirectDraw7_EnumDisplayModes(dxdata.maindd, flags, NULL, NULL, callback); + return result; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_CurrentWidth(void) +HRESULT DirectDraw_EnumDisplays(LPDDENUMCALLBACKEX callback) { - DWORD width; - width = DirectDrawState.current.desc.dwWidth; - return width; + HRESULT result; + result = DirectDrawEnumerateEx (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); + return result; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -DWORD DirectDraw_CurrentHeight(void) +DWORD DirectDraw_CurrentWidth (void) +{ + return dxdata.native.dwWidth; +} +DWORD DirectDraw_CurrentHeight (void) { - DWORD height; - height = DirectDrawState.current.desc.dwHeight; - return height; + return dxdata.native.dwHeight; +} +DWORD DirectDraw_GetCurrentDepth (void) +{ + return dxdata.native.ddpfPixelFormat.dwRGBBitCount; } +static LPDIRECTDRAWSURFACE7 getlocksurface (void) +{ + if (dxdata.backbuffers > 0 && currprefs.gfx_afullscreen > 0 && !WIN32GFX_IsPicassoScreen ()) + return dxdata.flipping[0]; + return dxdata.secondary; +} + +int DirectDraw_SurfaceLock (void) +{ + int ok; + if (getlocksurface () == NULL) + return 0; + if (dxdata.lockcnt > 0) + return 1; + ok = locksurface (getlocksurface (), &dxdata.locksurface); + if (ok) + dxdata.lockcnt++; + return ok; +} +void DirectDraw_SurfaceUnlock (void) +{ + if (dxdata.lockcnt == 0) + return; + dxdata.lockcnt--; + unlocksurface (getlocksurface ()); +} + +void *DirectDraw_GetSurfacePointer (void) +{ + return dxdata.locksurface.lpSurface; +} +DWORD DirectDraw_GetSurfacePitch (void) +{ + return dxdata.locksurface.lPitch; +} +int DirectDraw_IsLocked (void) +{ + return dxdata.lockcnt; +} +DWORD DirectDraw_GetPixelFormatBitMask(DirectDraw_Mask_e mask) +{ + DWORD result = 0; + switch(mask) + { + case red_mask: + result = dxdata.native.ddpfPixelFormat.dwRBitMask; + break; + case green_mask: + result = dxdata.native.ddpfPixelFormat.dwGBitMask; + break; + case blue_mask: + result = dxdata.native.ddpfPixelFormat.dwBBitMask; + break; + } + return result; +} +DWORD DirectDraw_GetPixelFormat (void) +{ + return DirectDraw_GetSurfacePixelFormat (&dxdata.native); +} +DWORD DirectDraw_GetBytesPerPixel (void) +{ + return (dxdata.native.ddpfPixelFormat.dwRGBBitCount + 7) >> 3; +} + +HRESULT DirectDraw_GetDC(HDC *hdc) +{ + HRESULT result; + result = IDirectDrawSurface7_GetDC (getlocksurface (), hdc); + return result; +} +HRESULT DirectDraw_ReleaseDC(HDC hdc) +{ + HRESULT result; + result = IDirectDrawSurface7_ReleaseDC (getlocksurface (), hdc); + return result; +} int DirectDraw_GetVerticalBlankStatus (void) { BOOL status; - if (FAILED(IDirectDraw7_GetVerticalBlankStatus (DirectDrawState.directdraw.dd, &status))) + if (FAILED(IDirectDraw7_GetVerticalBlankStatus (dxdata.maindd, &status))) return -1; return status; } +void DirectDraw_GetPrimaryPixelFormat (DDSURFACEDESC2 *desc) +{ + memcpy (&desc->ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); + desc->dwFlags |= DDSD_PIXELFORMAT; +} +DWORD DirectDraw_CurrentRefreshRate (void) +{ + return dxdata.native.dwRefreshRate; +} -DWORD DirectDraw_CurrentRefreshRate(void) +HRESULT DirectDraw_FlipToGDISurface (void) { - DWORD height; - height = DirectDrawState.current.desc.dwRefreshRate; - return height; + return IDirectDraw7_FlipToGDISurface (dxdata.maindd); } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static int DirectDraw_BltFastStub4(LPDIRECTDRAWSURFACE7 dstsurf, DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect) +int DirectDraw_BlitToPrimary (RECT *rect) { int result = 0; HRESULT ddrval; - - while(FAILED(ddrval = IDirectDrawSurface7_BltFast(dstsurf, x, y, srcsurf, srcrect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT))) { + RECT srcrect, dstrect; + int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; + + if (rect) { + x = rect->left; + y = rect->top; + w = rect->right - rect->left; + h = rect->bottom - rect->top; + } + if (w > dxdata.swidth - x) + w = dxdata.swidth - x; + if (h > dxdata.sheight - y) + h = dxdata.sheight - y; + SetRect (&srcrect, x, y, x + w, y + h); + SetRect (&dstrect, x, y, x + w, y + h); + centerdstrect (&dstrect, &srcrect); + while (FAILED(ddrval = IDirectDrawSurface7_Blt (dxdata.primary, &dstrect, dxdata.secondary, &srcrect, DDBLT_WAIT, NULL))) { if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (dstsurf); - if (FAILED(ddrval)) - break; + ddrval = restoresurface (dxdata.primary); + if (FAILED (ddrval)) + return 0; } else if (ddrval != DDERR_SURFACEBUSY) { - write_log ("BltFastStub7(): DirectDrawSURFACE7_BltFast() failed with %s\n", DXError (ddrval)); + write_log ("DirectDraw_BlitToPrimary: %s\n", DXError (ddrval)); break; } } - if(SUCCEEDED(ddrval)) + if (SUCCEEDED(ddrval)) result = 1; return result; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_BltFast(surface_type_e dsttype, DWORD left, DWORD top, surface_type_e srctype, LPRECT srcrect) +static void quickblit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src) { - LPDIRECTDRAWSURFACE7 lpDDS4_dst, lpDDS4_src; - if(dsttype == primary_surface) { - lpDDS4_dst = DirectDrawState.primary.surface; - } else if (dsttype == temporary_surface) { - lpDDS4_dst = DirectDrawState.temporary.surface; - } else { - lpDDS4_dst = DirectDrawState.secondary.surface; - } - if(srctype == primary_surface) { - lpDDS4_src = DirectDrawState.primary.surface; - } else if (srctype == temporary_surface) { - lpDDS4_src = DirectDrawState.temporary.surface; - } else { - lpDDS4_src = DirectDrawState.secondary.surface; - } - return DirectDraw_BltFastStub4(lpDDS4_dst, left, top, lpDDS4_src, srcrect); -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -static HRESULT DirectDraw_BltStub(LPDIRECTDRAWSURFACE7 dstsurf, LPRECT dstrect, LPDIRECTDRAWSURFACE7 srcsurf, LPRECT srcrect, DWORD flags, LPDDBLTFX ddbltfx) -{ - int result = 0, errcnt = 0; HRESULT ddrval; - - while(FAILED(ddrval = IDirectDrawSurface7_Blt(dstsurf, dstrect, srcsurf, srcrect, flags, ddbltfx))) { - if (ddrval == DDERR_SURFACELOST) { - if (errcnt > 10) - return 1; - errcnt++; - ddrval = restoresurface (dstsurf); - if (FAILED(ddrval)) { + while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, NULL, src, NULL, DDBLT_WAIT, NULL))) { + if (ddrval == DDERR_SURFACELOST) { + ddrval = restoresurface (dst); + if (FAILED (ddrval)) break; - } - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log ("BltStub(): DirectDrawSURFACE7_Blt() failed with %s\n", DXError (ddrval)); + } else if (ddrval != DDERR_SURFACEBUSY) { + write_log ("quickblit: %s\n", DXError (ddrval)); break; } } - return ddrval; } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ - -int DirectDraw_Flip(int wait) +extern int vblank_skip; +static void flip (void) { int result = 0; HRESULT ddrval = DD_OK; DWORD flags = DDFLIP_WAIT; static int skip; - frame_time_t start; - start = read_processor_time (); - if (DirectDrawState.flipping == triple_buffer) { - if (!currprefs.gfx_afullscreen && !currprefs.gfx_avsync) { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); - } else if (currprefs.gfx_avsync) { + if (dxdata.backbuffers == 2) { + if (currprefs.gfx_avsync) { if (vblank_skip >= 0) { skip++; if (vblank_skip > skip) { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_NOVSYNC); } else { skip = 0; - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); - idletime += read_processor_time() - start; + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); } } else { if (flipinterval_supported) { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_INTERVAL2); - idletime += read_processor_time() - start; + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); } else { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); - idletime += read_processor_time() - start; - result = DirectDraw_BltFast(tertiary_surface, 0, 0, primary_surface, NULL); - start = read_processor_time(); - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); - idletime += read_processor_time() - start; + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); + quickblit (dxdata.flipping[1], dxdata.primary); + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); } } } else { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); + ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); } - } else if(DirectDrawState.flipping == double_buffer) { - if (!currprefs.gfx_afullscreen && !currprefs.gfx_avsync) { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags | DDFLIP_NOVSYNC); - } else { - ddrval = IDirectDrawSurface7_Flip(DirectDrawState.primary.surface, NULL, flags); - idletime += read_processor_time() - start; - } - } else { - return 1; + quickblit (dxdata.flipping[1], dxdata.primary); + } else if(dxdata.backbuffers == 1) { + ddrval = IDirectDrawSurface7_Flip(dxdata.primary, NULL, flags); + quickblit (dxdata.flipping[0], dxdata.primary); } - if(SUCCEEDED(ddrval)) { - result = 1; - } else { - if (ddrval == DDERR_SURFACELOST) { - static int recurse; - IDirectDrawSurface7_Restore (DirectDrawState.primary.surface); - if (!recurse) { - recurse++; - DirectDraw_Flip (wait); - recurse--; - } - } else { - write_log ("FLIP: DirectDrawSurface_Flip() failed with %s\n", DXError (ddrval)); + if (ddrval == DDERR_SURFACELOST) { + static int recurse; + restoresurface (dxdata.primary); + if (!recurse) { + recurse++; + flip (); + recurse--; } + } else if(FAILED (ddrval)) { + write_log ("IDirectDrawSurface7_Flip: %s\n", DXError (ddrval)); } - return result; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_Blt(surface_type_e dsttype, LPRECT dstrect, - surface_type_e srctype, LPRECT srcrect, - DWORD flags, LPDDBLTFX fx) -{ - LPDIRECTDRAWSURFACE7 lpDDS4_dst, lpDDS4_src; - - if(dsttype == primary_surface) { - if(DirectDrawState.isoverlay) - lpDDS4_dst = DirectDrawState.overlay.surface; - else - lpDDS4_dst = DirectDrawState.primary.surface; - } else if(dsttype == secondary_surface) { - lpDDS4_dst = DirectDrawState.secondary.surface; - } else if(dsttype == tertiary_surface) { - lpDDS4_dst = DirectDrawState.tertiary.surface; - } else if(dsttype == temporary_surface) { - lpDDS4_dst = DirectDrawState.temporary.surface; - } else { - lpDDS4_dst = DirectDrawState.overlay.surface; - } - - if(srctype == primary_surface) { - lpDDS4_src = DirectDrawState.primary.surface; - } else if(srctype == secondary_surface) { - lpDDS4_src = DirectDrawState.secondary.surface; - } else if(srctype == tertiary_surface) { - lpDDS4_src = DirectDrawState.tertiary.surface; - } else if(srctype == temporary_surface) { - lpDDS4_src = DirectDrawState.temporary.surface; - } else if(srctype == overlay_surface) { - lpDDS4_src = DirectDrawState.overlay.surface; - } else { - lpDDS4_src = NULL; /* For using BltStub to do rect-fills */ - } - return DirectDraw_BltStub(lpDDS4_dst, dstrect, lpDDS4_src, srcrect, flags, fx); } -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_WaitForVerticalBlank(DWORD flags) -{ - HRESULT result; - result = IDirectDraw7_WaitForVerticalBlank(DirectDrawState.directdraw.dd, flags, NULL); - return result; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_EnumDisplayModes(DWORD flags, LPDDENUMMODESCALLBACK2 callback) -{ - HRESULT result; - result = IDirectDraw7_EnumDisplayModes(DirectDrawState.directdraw.dd, flags, NULL, NULL, callback); - return result; -} - -HRESULT DirectDraw_EnumDisplays(LPDDENUMCALLBACKEX callback ) -{ - HRESULT result; - result = DirectDrawEnumerateEx (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); - return result; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_FlipToGDISurface(void) -{ - HRESULT result = DDERR_GENERIC; - if(DirectDrawState.initialized) { - result = IDirectDraw7_FlipToGDISurface(DirectDrawState.directdraw.dd); - } - return result; -} -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_GetDC(HDC *hdc, surface_type_e surface) +int DirectDraw_Flip (int wait) { - HRESULT result = ~DD_OK; - if(surface == primary_surface) - result = IDirectDrawSurface7_GetDC (DirectDrawState.primary.surface, hdc); - else if (surface == overlay_surface) - result = IDirectDrawSurface7_GetDC (DirectDrawState.overlay.surface, hdc); - else if (surface == secondary_surface) - result = IDirectDrawSurface7_GetDC (DirectDrawState.secondary.surface, hdc); - return result; -} - -/* - * FUNCTION: - * - * PURPOSE: - * - * PARAMETERS: - * - * RETURNS: - * - * NOTES: - * - * HISTORY: - * 1999.08.02 Brian King Creation - * - */ -HRESULT DirectDraw_ReleaseDC (HDC hdc, surface_type_e surface) -{ - HRESULT result; - if (surface == primary_surface) - result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.primary.surface, hdc); - else if (surface == overlay_surface) - result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.overlay.surface, hdc); - else - result = IDirectDrawSurface7_ReleaseDC(DirectDrawState.secondary.surface, hdc); - return result; -} - -extern int display_change_requested; - -HRESULT DirectDraw_UpdateOverlay(RECT sr, RECT dr) -{ - HRESULT result = DD_OK; - - if (DirectDrawState.isoverlay && DirectDrawState.overlay.surface) { - if ((drivercaps.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && drivercaps.dwAlignBoundarySrc) - sr.left = (sr.left + drivercaps.dwAlignBoundarySrc / 2) & ~(drivercaps.dwAlignBoundarySrc - 1); - if ((drivercaps.dwCaps & DDCAPS_ALIGNSIZESRC) && drivercaps.dwAlignSizeSrc) - sr.right = sr.left + (sr.right - sr.left + drivercaps.dwAlignSizeSrc / 2) & ~(drivercaps.dwAlignSizeSrc - 1); - if ((drivercaps.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && drivercaps.dwAlignBoundaryDest) - dr.left = (dr.left + drivercaps.dwAlignBoundaryDest / 2) & ~(drivercaps.dwAlignBoundaryDest - 1); - if ((drivercaps.dwCaps & DDCAPS_ALIGNSIZEDEST) && drivercaps.dwAlignSizeDest) - dr.right = dr.left + (dr.right - dr.left) & ~(drivercaps.dwAlignSizeDest - 1); - result = IDirectDrawSurface7_UpdateOverlay(DirectDrawState.overlay.surface, &sr, DirectDrawState.primary.surface, &dr, overlayflags, &overlayfx); - - } - if (FAILED(result)) { - if (result == DDERR_SURFACELOST) - display_change_requested++; - write_log ("UpdateOverlay failed %s\n", DXError (result)); - } - return DD_OK; -} - -char *outGUID (GUID *guid) -{ - static char gb[64]; - if (guid == NULL) - return "NULL"; - sprintf(gb, "%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X", - guid->Data1, guid->Data2, guid->Data3, - guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], - guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); - return gb; -} - -int DirectDraw_GetPrimaryPixelFormat (LPDDPIXELFORMAT ddpf) -{ - surface_type_e surface_type; - HRESULT ddrval; - - surface_type = DirectDraw_GetLockableType (); - ddpf->dwSize = sizeof (DDPIXELFORMAT); - if (surface_type == overlay_surface) - ddrval = IDirectDrawSurface7_GetPixelFormat (DirectDrawState.overlay.surface, ddpf); - else - ddrval = IDirectDrawSurface7_GetPixelFormat (DirectDrawState.primary.surface, ddpf); - if (FAILED(ddrval)) { - write_log ("GetPixelFormat failed\n%s\n", DXError (ddrval)); - return 0; + if (getlocksurface () != dxdata.secondary) { + flip (); + } else { + DirectDraw_BlitToPrimary (NULL); } return 1; } diff --git a/od-win32/dxwrap.h b/od-win32/dxwrap.h index de338984..1ae3d1e7 100755 --- a/od-win32/dxwrap.h +++ b/od-win32/dxwrap.h @@ -3,6 +3,26 @@ #include "ddraw.h" +struct ddstuff +{ + int ddinit; + int ddzeroguid; + GUID ddguid; + LPDIRECTDRAW olddd; + LPDIRECTDRAW7 maindd; + LPDIRECTDRAWCLIPPER dclip; + LPDIRECTDRAWSURFACE7 primary, secondary, flipping[2]; + int fsmodeset, backbuffers; + int width, height, depth, freq; + int swidth, sheight; + DDSURFACEDESC2 native; + DDSURFACEDESC2 locksurface; + int lockcnt; + DWORD pitch; + HWND hwnd; +}; +extern struct ddstuff dxdata; + struct ScreenResolution { uae_u32 width; /* in pixels */ @@ -34,26 +54,6 @@ struct MultiDisplay { }; extern struct MultiDisplay Displays[MAX_DISPLAYS]; -typedef enum { - BLIT_FALSE, - BLIT_NOR, - BLIT_ONLYDST, - BLIT_NOTSRC, - BLIT_ONLYSRC, - BLIT_NOTDST, - BLIT_EOR, - BLIT_NAND, - BLIT_AND, - BLIT_NEOR, - BLIT_DST, - BLIT_NOTONLYSRC, - BLIT_SRC, - BLIT_NOTONLYDST, - BLIT_OR, - BLIT_TRUE, - BLIT_LAST -} BLIT_OPCODE; - /* Types for RGBFormat used */ typedef enum { RGBFB_NONE, /* no valid RGB format (should not happen) */ @@ -114,8 +114,6 @@ typedef enum { #define RGBMASK_24BIT (RGBFF_R8G8B8 | RGBFF_B8G8R8) #define RGBMASK_32BIT (RGBFF_A8R8G8B8 | RGBFF_A8B8G8R8 | RGBFF_R8G8B8A8 | RGBFF_B8G8R8A8) -/************************************************************************/ - #define RGBFF_PLANAR RGBFF_NONE #define RGBFF_CHUNKY RGBFF_CLUT @@ -129,130 +127,44 @@ typedef enum blue_mask } DirectDraw_Mask_e; -typedef enum -{ - invalid_surface, - primary_surface, - secondary_surface, - tertiary_surface, - overlay_surface, - lockable_surface, - temporary_surface -} surface_type_e; - -typedef enum -{ - single_buffer, - double_buffer, - triple_buffer -} flipping; - -struct DirectDrawSurfaceMapper -{ - int initialized; - int fullscreen; - int isoverlay; - int flipping; - int locked; - int modeset; - HWND window; - struct - { - LPDIRECTDRAW ddx; - LPDIRECTDRAW7 dd; - } directdraw; - struct - { - LPDIRECTDRAWSURFACE7 surface; - DDSURFACEDESC2 desc; - } primary; - struct - { - LPDIRECTDRAWSURFACE7 surface; - DDSURFACEDESC2 desc; - } secondary; - struct - { - LPDIRECTDRAWSURFACE7 surface; - DDSURFACEDESC2 desc; - } tertiary; - struct - { - LPDIRECTDRAWSURFACE7 surface; - DDSURFACEDESC2 desc; - } overlay; - struct - { - LPDIRECTDRAWSURFACE7 surface; - DDSURFACEDESC2 desc; - } temporary; - struct - { - DDSURFACEDESC2 desc; - } current; - struct - { - LPDIRECTDRAWSURFACE7 surface; - LPDDSURFACEDESC2 lpdesc; - } lockable; - LPDIRECTDRAWCLIPPER lpDDC; - LPDIRECTDRAWPALETTE lpDDP; - LPDIRECTDRAWPALETTE lpOverlayDDP; - surface_type_e surface_type; -}; -HRESULT DirectDraw_CreateOverlaySurface(int width, int height, int bits, int type); -int DirectDraw_Start( GUID *); -void DirectDraw_Release( void ); -HRESULT DirectDraw_SetCooperativeLevel( HWND window, int want_fullscreen ); -BOOL DirectDraw_GetCooperativeLevel( HWND *window, int *fullscreen ); -HRESULT DirectDraw_SetDisplayMode( int width, int height, int bits, int freq ); -HRESULT DirectDraw_GetDisplayMode( void ); -HRESULT DirectDraw_CreateClipper( void ); -HRESULT DirectDraw_GetCaps( DDCAPS_DX7 *driver_caps, DDCAPS_DX7 *hel_caps ); -HRESULT DirectDraw_CreateSurface( int width, int height ); -void DirectDraw_ClearSurfaces( void ); -HRESULT DirectDraw_SetClipper( HWND hWnd ); -HRESULT DirectDraw_GetClipList( LPRGNDATA cliplist, LPDWORD size ); -HRESULT DirectDraw_CreatePalette( LPPALETTEENTRY pal ); -HRESULT DirectDraw_SetPalette( int remove ); -HRESULT DirectDraw_SetPaletteEntries( int start, int count, PALETTEENTRY *palette ); -HRESULT DirectDraw_WaitForVerticalBlank( DWORD flags ); -HRESULT DirectDraw_EnumDisplayModes( DWORD flags, LPDDENUMMODESCALLBACK2 callback ); -HRESULT DirectDraw_EnumDisplays(LPDDENUMCALLBACKEX callback ); -HRESULT DirectDraw_FlipToGDISurface( void ); -HRESULT DirectDraw_GetDC( HDC *hdc, surface_type_e surface ); -HRESULT DirectDraw_ReleaseDC( HDC hdc, surface_type_e surface ); -int DirectDraw_Flip( int ); -HRESULT DirectDraw_UpdateOverlay(RECT sr, RECT dr); -HRESULT DirectDraw_Blt( surface_type_e dsttype, LPRECT dstrect, surface_type_e srctype, LPRECT srcrect, DWORD flags, LPDDBLTFX fx ); -HRESULT DirectDraw_BltFast( surface_type_e dsttype, DWORD left, DWORD top, surface_type_e srctype, LPRECT srcrect ); -DWORD DirectDraw_GetPixelFormatBitMask( DirectDraw_Mask_e mask ); -RGBFTYPE DirectDraw_GetPixelFormat( void ); -DWORD DirectDraw_GetPixelFormatFlags( void ); -DWORD DirectDraw_GetSurfaceFlags( void ); -DWORD DirectDraw_GetSurfaceBitCount( void ); -DWORD DirectDraw_GetPrimaryBitCount( void ); -void DirectDraw_GetPrimaryWidthHeight(int *w, int *h); -int DirectDraw_DetermineLocking( int wantfull ); -int DirectDraw_GetBytesPerPixel( void ); -RGBFTYPE DirectDraw_GetSurfacePixelFormat( LPDDSURFACEDESC2 surface ); -surface_type_e DirectDraw_GetLockableType( void ); -int DirectDraw_SurfaceLock( surface_type_e surface_type ); -BOOL DirectDraw_IsLocked( void ); -char *DirectDraw_GetSurfacePointer( void ); -LONG DirectDraw_GetSurfacePitch( void ); -DWORD DirectDraw_CurrentWidth( void ); -DWORD DirectDraw_CurrentHeight( void ); -DWORD DirectDraw_CurrentRefreshRate (void); -int DirectDraw_GetVerticalBlankStatus (void); -extern struct DirectDrawSurfaceMapper DirectDrawState; -extern int DirectDraw_GetPrimaryPixelFormat (LPDDPIXELFORMAT ddpf); - -extern void ddraw_unlockscr (void); -#define DirectDraw_SurfaceUnlock() ddraw_unlockscr() - extern const char *DXError (HRESULT hr); - extern char *outGUID (GUID *guid); +HRESULT DirectDraw_GetDisplayMode (void); +void DirectDraw_Release(void); +int DirectDraw_Start(GUID *guid); +void clearsurface(LPDIRECTDRAWSURFACE7 surf); +int locksurface (LPDIRECTDRAWSURFACE7 surf, LPDDSURFACEDESC2 desc); +void unlocksurface (LPDIRECTDRAWSURFACE7 surf); +LPDIRECTDRAWSURFACE7 allocsurface (int width, int height); +void freesurface (LPDIRECTDRAWSURFACE7 surf); +void DirectDraw_FreeMainSurface (void); +HRESULT DirectDraw_CreateMainSurface (int width, int height); +HRESULT DirectDraw_SetDisplayMode(int width, int height, int bits, int freq); +HRESULT DirectDraw_SetCooperativeLevel (HWND window, int fullscreen); +HRESULT DirectDraw_CreateClipper (void); +HRESULT DirectDraw_SetClipper(HWND hWnd); +RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface); +HRESULT DirectDraw_EnumDisplayModes(DWORD flags, LPDDENUMMODESCALLBACK2 callback); +HRESULT DirectDraw_EnumDisplays(LPDDENUMCALLBACKEX callback); +DWORD DirectDraw_CurrentWidth (void); +DWORD DirectDraw_CurrentHeight (void); +DWORD DirectDraw_GetCurrentDepth (void); +int DirectDraw_SurfaceLock (void); +void DirectDraw_SurfaceUnlock (void); +void *DirectDraw_GetSurfacePointer (void); +DWORD DirectDraw_GetSurfacePitch (void); +int DirectDraw_IsLocked (void); +DWORD DirectDraw_GetPixelFormatBitMask (DirectDraw_Mask_e mask); +DWORD DirectDraw_GetPixelFormat (void); +DWORD DirectDraw_GetBytesPerPixel (void); +HRESULT DirectDraw_GetDC(HDC *hdc); +HRESULT DirectDraw_ReleaseDC(HDC hdc); +int DirectDraw_GetVerticalBlankStatus (void); +DWORD DirectDraw_CurrentRefreshRate (void); +void DirectDraw_GetPrimaryPixelFormat (DDSURFACEDESC2 *desc); +HRESULT DirectDraw_FlipToGDISurface (void); +int DirectDraw_Flip (int wait); +int DirectDraw_BlitToPrimary (RECT *rect); #endif + diff --git a/od-win32/dxwrap_old.h b/od-win32/dxwrap_old.h new file mode 100755 index 00000000..de338984 --- /dev/null +++ b/od-win32/dxwrap_old.h @@ -0,0 +1,258 @@ +#ifndef __DXWRAP_H__ +#define __DXWRAP_H__ + +#include "ddraw.h" + +struct ScreenResolution +{ + uae_u32 width; /* in pixels */ + uae_u32 height; /* in pixels */ +}; + +#define MAX_PICASSO_MODES 300 +#define MAX_REFRESH_RATES 100 +struct PicassoResolution +{ + struct ScreenResolution res; + int depth; /* depth in bytes-per-pixel */ + int residx; + int refresh[MAX_REFRESH_RATES]; /* refresh-rates in Hz */ + char name[25]; + /* Bit mask of RGBFF_xxx values. */ + uae_u32 colormodes; +}; +extern struct PicassoResolution *DisplayModes; +extern GUID *displayGUID; + +#define MAX_DISPLAYS 10 +struct MultiDisplay { + int primary, disabled, gdi; + GUID guid; + char *name; + struct PicassoResolution *DisplayModes; + RECT rect; +}; +extern struct MultiDisplay Displays[MAX_DISPLAYS]; + +typedef enum { + BLIT_FALSE, + BLIT_NOR, + BLIT_ONLYDST, + BLIT_NOTSRC, + BLIT_ONLYSRC, + BLIT_NOTDST, + BLIT_EOR, + BLIT_NAND, + BLIT_AND, + BLIT_NEOR, + BLIT_DST, + BLIT_NOTONLYSRC, + BLIT_SRC, + BLIT_NOTONLYDST, + BLIT_OR, + BLIT_TRUE, + BLIT_LAST +} BLIT_OPCODE; + +/* Types for RGBFormat used */ +typedef enum { + RGBFB_NONE, /* no valid RGB format (should not happen) */ + RGBFB_CLUT, /* palette mode, set colors when opening screen using + tags or use SetRGB32/LoadRGB32(...) */ + RGBFB_R8G8B8, /* TrueColor RGB (8 bit each) */ + RGBFB_B8G8R8, /* TrueColor BGR (8 bit each) */ + RGBFB_R5G6B5PC, /* HiColor16 (5 bit R, 6 bit G, 5 bit B), + format: gggbbbbbrrrrrggg */ + RGBFB_R5G5B5PC, /* HiColor15 (5 bit each), format: gggbbbbb0rrrrrgg */ + RGBFB_A8R8G8B8, /* 4 Byte TrueColor ARGB (A unused alpha channel) */ + RGBFB_A8B8G8R8, /* 4 Byte TrueColor ABGR (A unused alpha channel) */ + RGBFB_R8G8B8A8, /* 4 Byte TrueColor RGBA (A unused alpha channel) */ + RGBFB_B8G8R8A8, /* 4 Byte TrueColor BGRA (A unused alpha channel) */ + RGBFB_R5G6B5, /* HiColor16 (5 bit R, 6 bit G, 5 bit B), + format: rrrrrggggggbbbbb */ + RGBFB_R5G5B5, /* HiColor15 (5 bit each), format: 0rrrrrgggggbbbbb */ + RGBFB_B5G6R5PC, /* HiColor16 (5 bit R, 6 bit G, 5 bit B), + format: gggrrrrrbbbbbggg */ + RGBFB_B5G5R5PC, /* HiColor15 (5 bit each), format: gggrrrrr0bbbbbbgg */ + + /* By now, the following formats are for use with a hardware window only + (bitmap operations may be implemented incompletely) */ + + RGBFB_Y4U2V2, /* 2 Byte TrueColor YUV (CCIR recommendation CCIR601). + Each two-pixel unit is stored as one longword + containing luminance (Y) for each of the two pixels, + and chrominance (U,V) for alternate pixels. + The missing chrominance values are generated by + interpolation. (Y1-U0-Y0-V0) */ + RGBFB_Y4U1V1, /* 1 Byte TrueColor ACCUPAK. Four adjacent pixels form + a packet of 5 bits Y (luminance) each pixel and 6 bits + U and V (chrominance) shared by the four pixels */ + + RGBFB_MaxFormats +} RGBFTYPE; + +#define RGBFF_NONE (1<> 20); - if (p96mode) + if (currprefs.gfxmem_size) write_log ("NATMEM: P96 special area: 0x%p-0x%p (%08x %dM)\n", p96mem_offset, (uae_u8*)p96mem_offset + currprefs.gfxmem_size, currprefs.gfxmem_size, currprefs.gfxmem_size >> 20); @@ -207,9 +201,7 @@ void mapped_free(uae_u8 *mem) { shmpiece *x = shm_start; - if (mem == filesysory || (!p96mode && mem == p96fakeram)) { - xfree (p96fakeram); - p96fakeram = NULL; + if (mem == filesysory) { while(x) { if (mem == x->native_address) { int shmid = x->id; @@ -327,21 +319,10 @@ void *shmat(int shmid, void *shmaddr, int shmflg) } if(!strcmp(shmids[shmid].name,"gfx")) { got = TRUE; - if (p96mode) { - p96special = TRUE; - p96ram_start = p96mem_offset - natmem_offset; - shmaddr = natmem_offset + p96ram_start; - size += BARRIER; - } else { - extern void p96memstart(void); - p96memstart(); - shmaddr = natmem_offset + p96ram_start; - virtualfreewithlock(shmaddr, size, MEM_DECOMMIT); - xfree(p96fakeram); - result = p96fakeram = xcalloc (size + 4096, 1); - shmids[shmid].attached = result; - return result; - } + p96special = TRUE; + p96ram_start = p96mem_offset - natmem_offset; + shmaddr = natmem_offset + p96ram_start; + size += BARRIER; } if(!strcmp(shmids[shmid].name,"bogo")) { shmaddr=natmem_offset+0x00C00000; diff --git a/od-win32/picasso96_win.c b/od-win32/picasso96_win.c index 1cfc012e..6b0ce683 100755 --- a/od-win32/picasso96_win.c +++ b/od-win32/picasso96_win.c @@ -56,13 +56,11 @@ static int hwsprite = 0; #include "picasso96_win.h" #include "win32gfx.h" -extern int p96mode; //#define P96TRACING_ENABLED 1 int p96hack_vpos, p96hack_vpos2, p96refresh_active; int have_done_picasso; /* For the JIT compiler */ -static int vsyncgfxwrite = -1; -static int p96syncrate, vsyncgfxcount; +static int p96syncrate; int p96hsync_counter, palette_changed; #if defined(X86_MSVC_ASSEMBLY) #define SWAPSPEEDUP @@ -72,33 +70,18 @@ int p96hsync_counter, palette_changed; #define P96TRACING_ENABLED 1 #define P96TRACING_LEVEL 1 #endif -#define LOCK_UNLOCK_MADNESS //need for 7 times faster linedraw -#define PIXEL_LOCK //and scrollable screens -#define MAXFLUSHPIXEL 2000 //pixel draw in a lock static void flushpixels(void); static void flushpixels_lock(void); #ifdef P96TRACING_ENABLED #define P96TRACE(x) do { write_log x; } while(0) +#define P96TRACE_SPR(x) do { write_log x; } while(0) #else #define P96TRACE(x) +#define P96TRACE_SPR(x) #endif -#define P96TRACE_SPR(x) do { write_log x; } while(0) #define GetBytesPerPixel(x) GetBytesPerPixel2(x,__FILE__,__LINE__) -#if defined(JIT) -#define P96_SM_RW if (p96mode == 0) special_mem |= PIC_READ | PIC_WRITE; -#define P96_SM_R special_mem |= PIC_READ; -#define P96_SM_W special_mem |= PIC_WRITE; -#else -#define P96_SM_RW -#define P96_SM_R -#define P96_SM_W -#endif - -static void REGPARAM2 gfxmem_lput (uaecptr, uae_u32) REGPARAM; -static void REGPARAM2 gfxmem_wput (uaecptr, uae_u32) REGPARAM; -static void REGPARAM2 gfxmem_bput (uaecptr, uae_u32) REGPARAM; static void REGPARAM2 gfxmem_lputx (uaecptr, uae_u32) REGPARAM; static void REGPARAM2 gfxmem_wputx (uaecptr, uae_u32) REGPARAM; static void REGPARAM2 gfxmem_bputx (uaecptr, uae_u32) REGPARAM; @@ -122,10 +105,31 @@ uae_u32 p96_rgbx16[65536]; static LPDIRECTDRAWSURFACE7 cursorsurface; static int cursorwidth, cursorheight; -static uae_u32 cursorrgb[4]; +static uae_u32 cursorrgb[4], cursorrgbn[4]; static int reloadcursor, cursorvisible, cursordeactivate; static uaecptr cursorbi; + +typedef enum { + BLIT_FALSE, + BLIT_NOR, + BLIT_ONLYDST, + BLIT_NOTSRC, + BLIT_ONLYSRC, + BLIT_NOTDST, + BLIT_EOR, + BLIT_NAND, + BLIT_AND, + BLIT_NEOR, + BLIT_DST, + BLIT_NOTONLYSRC, + BLIT_SRC, + BLIT_NOTONLYDST, + BLIT_OR, + BLIT_TRUE, + BLIT_LAST +} BLIT_OPCODE; + #include "win32gui.h" #include "resource.h" #define UAE_RTG_LIBRARY_VERSION 40 @@ -165,43 +169,19 @@ static uae_u32 p2ctab[256][2]; static int set_gc_called = 0, init_picasso_screen_called = 0; //fastscreen static uaecptr oldscr = 0; -#ifdef _DEBUG -void PICASSO96_Unlock2(char *filename, int linenum) -#else void PICASSO96_Unlock(void) -#endif { -#ifdef LOCK_UNLOCK_MADNESS -#if defined(P96TRACING_ENABLED) && P96TRACING_LEVEL > 1 - // This format of output lets you double-click and jump to file/line - write_log ( "%s(%d) : calling P96 UNLOCK with picasso_on=%d\n", filename, linenum, picasso_on); -#endif - if(picasso_on) - { -#ifdef PIXEL_LOCK + if(picasso_on) { flushpixels_lock(); -#endif gfx_unlock_picasso (); } -#endif } -#ifdef _DEBUG -void PICASSO96_Lock2(char *filename, int linenum) -#else void PICASSO96_Lock(void) -#endif { -#ifdef LOCK_UNLOCK_MADNESS -#if defined(P96TRACING_ENABLED) && P96TRACING_LEVEL > 1 - // This format of output lets you double-click and jump to file/line - write_log ( "%s(%d) : calling P96 LOCK with picasso_on=%d\n", filename, linenum, picasso_on); -#endif - if(picasso_on) - { + if(picasso_on) { picasso96_state.HostAddress = gfx_lock_picasso (); } -#endif } static void endianswap (uae_u32 *vp, int bpp) @@ -524,260 +504,6 @@ static void AmigaListAddTail (uaecptr l, uaecptr n) put_long (l + 8, n); // l->lh_TailPred = n; } -/* -* Functions to perform an action on the real screen -*/ - -/* -* Fill a rectangle on the screen. src points to the start of a line of the -* filled rectangle in the frame buffer; it can be used as a memcpy source if -* there is no OS specific function to fill the rectangle. -*/ -static void do_fillrect (uae_u8 *src, unsigned int x, unsigned int y, - unsigned int width, unsigned int height, - uae_u32 pen, int Bpp, RGBFTYPE rgbtype) -{ - uae_u8 *dst; - - /* Try OS specific fillrect function here; and return if successful. Make sure we adjust for - * the pen values if we're doing 8-bit display-emulation on a 16-bit or higher screen. */ - -#ifdef PIXEL_LOCK - flushpixels(); -#endif - -#if USEDX - if(picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) { - if(DX_Fill(x, y, width, height, pen, rgbtype)) - return; - } else { - if(DX_Fill(x, y, width, height, picasso_vidinfo.clut[src[0]], rgbtype)) - return; - } - P96TRACE(("P96_WARNING: do_fillrect() using fall-back routine!\n")); -#endif - - if(y + height > picasso_vidinfo.height) - height = picasso_vidinfo.height - y; - if(x + width > picasso_vidinfo.width) - width = picasso_vidinfo.width - x; - - DX_Invalidate (x, y, width, height); - if (! picasso_vidinfo.extra_mem) - return; - -#ifdef LOCK_UNLOCK_MADNESS - PICASSO96_Lock(); - dst = picasso96_state.HostAddress; -#else - dst = gfx_lock_picasso (); -#endif - if (!dst) - goto out; - - width *= Bpp; - dst += y * picasso_vidinfo.rowbytes + x * picasso_vidinfo.pixbytes; - if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) { - if(Bpp == 1) { - while (height-- > 0) { - memset(dst, pen, width); - dst += picasso_vidinfo.rowbytes; - } - } else { - while (height-- > 0) { - memcpy (dst, src, width); - dst += picasso_vidinfo.rowbytes; - } - } - } else { - int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat); - if (picasso96_state.RGBFormat != RGBFB_CHUNKY) { - write_log ("ERROR - do_fillrect() failure1 (%d)\n", picasso96_state.RGBFormat); - goto out; - } - - while (height-- > 0) { - unsigned int i; - switch (psiz) - { - case 2: - for (i = 0; i < width; i++) - *((uae_u16 *)dst + i) = picasso_vidinfo.clut[src[i]]; - break; - case 4: - for (i = 0; i < width; i++) - *((uae_u32 *)dst + i) = picasso_vidinfo.clut[src[i]]; - break; - default: - write_log ("ERROR - do_fillrect() failure2 (%d), psize\n"); - goto out; - break; - } - dst += picasso_vidinfo.rowbytes; - } - } -out:; -#ifndef LOCK_UNLOCK_MADNESS - gfx_unlock_picasso (); -#else - PICASSO96_Unlock(); -#endif -} - -/* -* This routine modifies the real screen buffer after a blit has been -* performed in the save area. If can_do_blit is nonzero, the blit can -* be performed within the real screen buffer; otherwise, this routine -* must do it by hand using the data in the frame-buffer, calculated using -* the RenderInfo data and our coordinates. -*/ -static void do_blit (struct RenderInfo *ri, int Bpp, - unsigned int srcx, unsigned int srcy, unsigned int dstx, unsigned int dsty, - unsigned int width, unsigned int height, BLIT_OPCODE opcode, int can_do_blit) -{ - uae_u8 *dstp, *srcp; - int orig_height = height; - - if (picasso96_state.BigAssBitmap && can_do_blit) { - srcx = dstx; - srcy = dsty; - can_do_blit = 0; - } //hack to use cpu rotines for scrolling in big Screens - if (picasso96_state.XOffset < 0) - can_do_blit = 0; - - dstx=dstx - picasso96_state.XOffset; - dsty=dsty - picasso96_state.YOffset; - if ((int)dstx <= 0) { - srcx = srcx - dstx; - dstx = 0; - } - if ((int)dsty <= 0) { - srcy = srcy-dsty; - dsty = 0; - } - -#ifdef LOCK_UNLOCK_MADNESS -#ifdef PIXEL_LOCK - flushpixels(); -#endif -#endif - - /* Is our x/y origin on-screen? */ - if(dsty >= picasso_vidinfo.height) - return; - if(dstx >= picasso_vidinfo.width) - return; - - /* Is our area in-range? */ - if(dsty + height >= picasso_vidinfo.height) - height = picasso_vidinfo.height - dsty; - if(dstx + width >= picasso_vidinfo.width) - width = picasso_vidinfo.width - dstx; - - if (can_do_blit) { - // - // Call OS blitting function that can do it in video memory. - // Should return if it was successful - // -#if USEDX - if(DX_Blit(srcx, srcy, dstx, dsty, width, height, opcode)) - return; -#endif - srcx = dstx; - srcy = dsty; - } -#ifdef LOCK_UNLOCK_MADNESS - PICASSO96_Lock(); -#endif - - srcp = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow; - - DX_Invalidate (dstx, dsty, width, height); - if (! picasso_vidinfo.extra_mem) { - #ifdef LOCK_UNLOCK_MADNESS - goto out; - #else - return; - #endif - } - -#ifdef LOCK_UNLOCK_MADNESS - dstp = picasso96_state.HostAddress; -#else - dstp = gfx_lock_picasso (); -#endif - if (dstp == 0) { - write_log ("WARNING: do_blit() couldn't lock\n"); - goto out; - } - - /* The areas can't overlap: the source is always in the Picasso frame buffer, - * and the destination is a different buffer owned by the graphics code. */ - dstp += dsty * picasso_vidinfo.rowbytes + dstx * picasso_vidinfo.pixbytes; - P96TRACE(("do_blit with srcp 0x%x, dstp 0x%x, dst_rowbytes %d, srcx %d, srcy %d, dstx %d, dsty %d, w %d, h %d, dst_pixbytes %d\n", - srcp, dstp, picasso_vidinfo.rowbytes, srcx, srcy, dstx, dsty, width, height, picasso_vidinfo.pixbytes)); - P96TRACE(("gfxmem is at 0x%x\n",gfxmemory)); - - if (picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) { - P96TRACE(("do_blit type-a\n")); - width *= Bpp; - while (height-- > 0) - { - memcpy (dstp, srcp, width); - srcp += ri->BytesPerRow; - dstp += picasso_vidinfo.rowbytes; - - } - } else { - int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat); - P96TRACE(("do_blit type-b\n")); - if (picasso96_state.RGBFormat != RGBFB_CHUNKY) { - write_log ("ERROR: do_blit() failure, %d!\n", picasso96_state.RGBFormat); - goto out; - } - while (height-- > 0) { - unsigned int i; - switch (psiz) - { - case 2: - for (i = 0; i < width; i++) - *((uae_u16 *)dstp + i) = picasso_vidinfo.clut[srcp[i]]; - break; - case 4: - for (i = 0; i < width; i++) - *((uae_u32 *)dstp + i) = picasso_vidinfo.clut[srcp[i]]; - break; - default: - write_log ("ERROR - do_blit() failure2, %d!\n", psiz); - goto out; - } - srcp += ri->BytesPerRow; - dstp += picasso_vidinfo.rowbytes; - } - } - out: -#ifndef LOCK_UNLOCK_MADNESS - gfx_unlock_picasso (); -#else - PICASSO96_Unlock(); -#endif - ; -} - -/* -* Invert a rectangle on the screen. a render-info is given, -* so that do_blit can be used if -* there is no OS specific function to invert the rectangle. -*/ -static void do_invertrect( struct RenderInfo *ri, int Bpp, int x, int y, int width, int height) -{ - /* if(DX_InvertRect(x, y, width, height)) - return;*/ //deactivate in 0.8.20 - P96TRACE(("do_invertrect falling back to do_blit!\n")); - do_blit (ri, Bpp, x, y, x, y, width, height, BLIT_SRC, 0); -} - static int renderinfo_is_current_screen (struct RenderInfo *ri) { if (! picasso_on) @@ -916,7 +642,7 @@ void picasso_handle_vsync (void) mouseupdate (); - if (vsyncgfxwrite < 0 && currprefs.chipset_refreshrate >= 100) { + if (currprefs.chipset_refreshrate >= 100) { vsynccnt++; if (vsynccnt < 2) return; @@ -924,29 +650,6 @@ void picasso_handle_vsync (void) } PICASSO96_Unlock(); - - if (vsyncgfxwrite == 1) { - static long blitcount; - vsyncgfxcount++; - if (vsyncgfxcount > 1) { - if (picasso_on) { - if (picasso96_state.RGBFormat == picasso_vidinfo.rgbformat - || picasso96_state.RGBFormat == RGBFB_CHUNKY) { - static frame_time_t cycles; - blitcount++; - cycles = read_processor_time(); - picasso_refresh(); - vsyncgfxcount = 0; - write_log ("%d Blitnum %.3fms\n", blitcount, - (read_processor_time() - cycles) * 1000 / (double)syncbase); - } - } - } - } - - setoverlay(1); - - } static int set_panning_called = 0; @@ -1004,16 +707,13 @@ void picasso_refresh (void) // Let's put a black-border around the case where we've got a sub-screen... if (!picasso96_state.BigAssBitmap) { if (picasso96_state.XOffset || picasso96_state.YOffset) - DX_Fill (0, 0, picasso96_state.Width, picasso96_state.Height, 0, - picasso96_state.RGBFormat); + DX_Fill (0, 0, picasso96_state.Width, picasso96_state.Height, 0); } } else { width = picasso96_state.Width; height = picasso96_state.Height; } flushpixels (); - if (!p96mode) - do_blit (&ri, picasso96_state.BytesPerPixel, 0, 0, 0, 0, width, height, BLIT_SRC, 0); } else { write_log ("ERROR - picasso_refresh() can't refresh!\n"); } @@ -1362,7 +1062,7 @@ uae_u32 REGPARAM2 picasso_SetSprite (struct regstruct *regs) cursordeactivate = 10; } result = 1; - write_log ("SetSprite: %d\n", activate); + P96TRACE_SPR (("SetSprite: %d\n", activate)); return result; } @@ -1403,33 +1103,18 @@ uae_u32 REGPARAM2 picasso_SetSpriteColor (struct regstruct *regs) uae_u8 red = m68k_dreg (regs, 1); uae_u8 green = m68k_dreg (regs, 2); uae_u8 blue = m68k_dreg (regs, 3); - uae_u32 v, vx; idx++; if (!hwsprite) return 0; if (idx >= 4) return 0; - v = (red << 16) | (green << 8) | (blue << 0); - switch (picasso_vidinfo.pixbytes) - { - case 1: - cursorrgb[0] = 0; - cursorrgb[idx] = idx; - break; - case 2: - vx = 0xff00ff; - cursorrgb[0] = p96_rgbx16[(((vx >> (16 + 3)) & 0x1f) << 11) | (((vx >> (8 + 2)) & 0x3f) << 5) | (((vx >> (0 + 3)) & 0x1f) << 0)]; - cursorrgb[idx] = p96_rgbx16[(((v >> (16 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (0 + 3)) & 0x1f) << 0)]; - break; - case 4: - cursorrgb[0] = 0xff00ff; - cursorrgb[idx] = v; - break; - } + cursorrgb[idx] = (red << 16) | (green << 8) | (blue << 0); + return 1; P96TRACE_SPR (("SetSpriteColor(%08x,%d:%02X%02X%02X)\n", bi, idx, red, green, blue)); return 1; } + /* SetSpriteImage: Synopsis: SetSpriteImage(bi, RGBFormat); @@ -1459,11 +1144,18 @@ compensate for this when accounting for hotspot offsets and sprite dimensions. static uae_u32 setspriteimage (uaecptr bi); static RECT cursor_r1, cursor_r2; static int mouseput; +static void recursor (HRESULT ddrval) +{ + if (ddrval == DDERR_SURFACELOST || ddrval == DDERR_DEVICEDOESNTOWNSURFACE) { + reloadcursor = 1; + setspriteimage (cursorbi); + } +} void picasso_putcursor (int sx, int sy, int sw, int sh) { int xdiff, ydiff, xdiff2, ydiff2; DWORD ddrval; - LPDIRECTDRAWSURFACE7 dstsurf = DirectDrawState.secondary.surface; + LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; if (cursorsurface == NULL || !cursorvisible) return; @@ -1512,9 +1204,8 @@ void picasso_putcursor (int sx, int sy, int sw, int sh) ddrval = IDirectDrawSurface7_Blt (cursorsurface, &cursor_r2, dstsurf, &cursor_r1, DDBLT_WAIT, NULL); if (FAILED(ddrval)) { - write_log ("Cursor surface blit1 failed: %08x %s\n", ddrval, DXError (ddrval)); - if (ddrval == DDERR_SURFACELOST) - setspriteimage (cursorbi); + write_log ("Cursor surface blit1 failed: %s\n", DXError (ddrval)); + recursor (ddrval); return; } @@ -1525,9 +1216,8 @@ void picasso_putcursor (int sx, int sy, int sw, int sh) ddrval = IDirectDrawSurface7_Blt (dstsurf, &cursor_r1, cursorsurface, &cursor_r2, DDBLT_WAIT | DDBLT_KEYSRC, NULL); if (FAILED(ddrval)) { - write_log ("Cursor surface blit2 failed: %08x %s\n", ddrval, DXError (ddrval)); - if (ddrval == DDERR_SURFACELOST) - setspriteimage (cursorbi); + write_log ("Cursor surface blit2 failed: %s\n", DXError (ddrval)); + recursor (ddrval); return; } @@ -1541,7 +1231,7 @@ void picasso_putcursor (int sx, int sy, int sw, int sh) void picasso_clearcursor (void) { DWORD ddrval; - LPDIRECTDRAWSURFACE7 dstsurf = DirectDrawState.secondary.surface; + LPDIRECTDRAWSURFACE7 dstsurf = dxdata.secondary; if (cursorsurface == NULL) return; @@ -1551,12 +1241,12 @@ void picasso_clearcursor (void) ddrval = IDirectDrawSurface7_Blt (dstsurf, &cursor_r1, cursorsurface, &cursor_r2, DDBLT_WAIT, NULL); if (FAILED(ddrval)) - write_log ("Cursor surface clearblit failed: %08x %s\n", ddrval, DXError (ddrval)); + write_log ("Cursor surface clearblit failed: %s\n", DXError (ddrval)); } static void putmousepixel (uae_u8 *d, int bpp, int idx) { - uae_u32 val = cursorrgb[idx]; + uae_u32 val = cursorrgbn[idx]; switch (bpp) { case 1: @@ -1571,6 +1261,31 @@ static void putmousepixel (uae_u8 *d, int bpp, int idx) } } +static void updatesprcolors (void) +{ + int i; + for (i = 1; i < 4; i++) { + uae_u32 v, vx; + v = cursorrgb[i]; + switch (picasso_vidinfo.pixbytes) + { + case 1: + cursorrgbn[0] = 0; + cursorrgbn[i] = i; + break; + case 2: + vx = 0xff00ff; + cursorrgbn[0] = p96_rgbx16[(((vx >> (16 + 3)) & 0x1f) << 11) | (((vx >> (8 + 2)) & 0x3f) << 5) | (((vx >> (0 + 3)) & 0x1f) << 0)]; + cursorrgbn[i] = p96_rgbx16[(((v >> (16 + 3)) & 0x1f) << 11) | (((v >> (8 + 2)) & 0x3f) << 5) | (((v >> (0 + 3)) & 0x1f) << 0)]; + break; + case 4: + cursorrgbn[0] = 0xff00ff; + cursorrgbn[i] = v; + break; + } + } +} + static uae_u32 setspriteimage (uaecptr bi) { DDSURFACEDESC2 desc; @@ -1597,6 +1312,7 @@ static uae_u32 setspriteimage (uaecptr bi) hiressprite = 2; if (flags & BIF_BIGSPRITE) doubledsprite = 1; + updatesprcolors (); P96TRACE_SPR (("SetSpriteImage(%08x,%08x,w=%d,h=%d,hires=%d,double=%d,%08x)\n", bi, get_long (bi + PSSO_BoardInfo_MouseImage), w, h, hiressprite - 1, doubledsprite, bi + PSSO_BoardInfo_MouseImage)); @@ -1686,13 +1402,12 @@ static uae_u32 setspriteimage (uaecptr bi) desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; desc.dwWidth = w; desc.dwHeight = h * 2; - if (DirectDraw_GetPrimaryPixelFormat (&desc.ddpfPixelFormat)) - desc.dwFlags |= DDSD_PIXELFORMAT; - desc.ddckCKSrcBlt.dwColorSpaceLowValue = cursorrgb[0]; - desc.ddckCKSrcBlt.dwColorSpaceHighValue = cursorrgb[0]; - ddrval = IDirectDraw7_CreateSurface (DirectDrawState.directdraw.dd, &desc, &cursorsurface, NULL); + DirectDraw_GetPrimaryPixelFormat (&desc); + desc.ddckCKSrcBlt.dwColorSpaceLowValue = cursorrgbn[0]; + desc.ddckCKSrcBlt.dwColorSpaceHighValue = cursorrgbn[0]; + ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &cursorsurface, NULL); if (FAILED(ddrval)) { - write_log ("Cursor surface creation failed: %08x %s\n", ddrval, DXError (ddrval)); + write_log ("Cursor surface creation failed: %s\n", DXError (ddrval)); return 0; } desc.dwSize = sizeof (desc); @@ -1700,7 +1415,7 @@ static uae_u32 setspriteimage (uaecptr bi) if (ddrval == DDERR_SURFACELOST) { ddrval = IDirectDrawSurface7_Restore (cursorsurface); if (FAILED(ddrval)) { - write_log ("sprite surface failed to restore: %08x %s\n", ddrval, DXError (ddrval)); + write_log ("sprite surface failed to restore: %s\n", DXError (ddrval)); goto end; } } @@ -2014,18 +1729,12 @@ void picasso96_alloc (TrapContext *ctx) picasso96_amemend = picasso96_amem + size; write_log("P96 RESINFO: %08X-%08X (%d,%d)\n", picasso96_amem, picasso96_amemend, cnt, size); - if (p96mode) { - xfree (gwwbuf); - GetSystemInfo (&si); - gwwpagesize = si.dwPageSize; - gwwbufsize = allocated_gfxmem / gwwpagesize + 1; - gwwpagemask = gwwpagesize - 1; - gwwbuf = xmalloc (gwwbufsize * sizeof (void*)); - vsyncgfxwrite = -1; - } else { - vsyncgfxwrite = 0; - } - write_log ("P96 VRAM MODE: %s\n", p96mode ? "Direct" : "Indirect"); + xfree (gwwbuf); + GetSystemInfo (&si); + gwwpagesize = si.dwPageSize; + gwwbufsize = allocated_gfxmem / gwwpagesize + 1; + gwwpagemask = gwwpagesize - 1; + gwwbuf = xmalloc (gwwbufsize * sizeof (void*)); } /**************************************** @@ -2049,7 +1758,7 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs) } amem = picasso96_amem; - put_word (AmigaBoardInfo + PSSO_BoardInfo_BitsPerCannon, DX_BitsPerCannon()); + put_word (AmigaBoardInfo + PSSO_BoardInfo_BitsPerCannon, 8); put_word (AmigaBoardInfo + PSSO_BoardInfo_RGBFormats, picasso96_pixel_format); put_long (AmigaBoardInfo + PSSO_BoardInfo_BoardType, BT_uaegfx); flags = get_long (AmigaBoardInfo + PSSO_BoardInfo_Flags); @@ -2177,12 +1886,18 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs) uae_u32 REGPARAM2 picasso_SetSwitch (struct regstruct *regs) { uae_u16 flag = m68k_dreg (regs, 0) & 0xFFFF; + char p96text[100]; /* Do not switch immediately. Tell the custom chip emulation about the * desired state, and wait for custom.c to call picasso_enablescreen * whenever it is ready to change the screen state. */ picasso_requested_on = flag; - write_log ("SetSwitch() - trying to show %s screen\n", flag ? "picasso96":"amiga"); + p96text[0] = 0; + if (flag) + sprintf (p96text, "Picasso96 %dx%dx%d (%dx%dx%d)", + picasso96_state.Width, picasso96_state.Height, picasso96_state.BytesPerPixel * 8, + picasso_vidinfo.width, picasso_vidinfo.height, picasso_vidinfo.pixbytes * 8); + write_log ("SetSwitch() - trying to show %s screen\n", flag ? p96text : "amiga"); /* Put old switch-state in D0 */ @@ -2197,7 +1912,6 @@ void picasso_enablescreen (int on) init_picasso_screen(); picasso_refresh (); - write_log ("SetSwitch() from threadid %d - showing %s screen\n", GetCurrentThreadId(), on ? "picasso96": "amiga"); checkrtglibrary(); } @@ -2459,14 +2173,6 @@ uae_u32 REGPARAM2 picasso_InvertRect (struct regstruct *regs) do_xor8 (uae_mem, width_in_bytes, xorval); } - if (vsyncgfxwrite == 0) { - if (renderinfo_is_current_screen (&ri)) { - if (mask == 0xFF) - do_invertrect(&ri, Bpp, X, Y, Width, Height); - else - do_blit(&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0); - } - } result = 1; } @@ -2496,14 +2202,11 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs) uae_u32 Pen = m68k_dreg (regs, 4); uae_u8 Mask = (uae_u8)m68k_dreg (regs, 5); RGBFTYPE RGBFormat = m68k_dreg (regs, 7); - uae_u8 *src; uae_u8 *oldstart; int Bpp; struct RenderInfo ri; uae_u32 result = 0; - P96_SM_RW; - if (CopyRenderInfoStructureA2U (renderinfo, &ri) && Y != 0xFFFF) { if (ri.RGBFormat != RGBFormat) write_log ("Weird Stuff!\n"); @@ -2520,25 +2223,6 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs) /* Do the fill-rect in the frame-buffer */ do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp, RGBFormat); - - /* Now we do the on-screen display, if renderinfo points to it */ - if (vsyncgfxwrite == 0 && renderinfo_is_current_screen (&ri)) { - src = ri.Memory + X * Bpp + Y * ri.BytesPerRow; - X = X - picasso96_state.XOffset; - Y = Y - picasso96_state.YOffset; - if((int)X < 0) { Width = Width + X; X = 0; } - if((int)Width < 1) return 1; - if((int)Y < 0) { Height = Height + Y; Y = 0; } - if((int)Height < 1) return 1; - /* Argh - why does P96Speed do this to me, with FillRect only?! */ - if(X < picasso96_state.Width && Y < picasso96_state.Height) { - if(X + Width > picasso96_state.Width) - Width = picasso96_state.Width - X; - if(Y + Height > picasso96_state.Height) - Height = picasso96_state.Height - Y; - do_fillrect(src, X, Y, Width, Height, Pen, Bpp, RGBFormat); - } - } result = 1; } else { @@ -2561,8 +2245,6 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs) } } } - if (vsyncgfxwrite == 0 && renderinfo_is_current_screen (&ri)) - do_blit(&ri, Bpp, X, Y, X, Y, Width, Height, BLIT_SRC, 0); result = 1; } } @@ -2648,23 +2330,6 @@ STATIC_INLINE int BlitRectHelper (void) /* Do our virtual frame-buffer memory first */ do_blitrect_frame_buffer (ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode); - /* Now we do the on-screen display, if renderinfo points to it */ - if (vsyncgfxwrite == 0) { - if (renderinfo_is_current_screen (dstri)) { - if (mask == 0xFF || Bpp > 1) { - if(can_do_visible_blit) - do_blit(dstri, Bpp, srcx, srcy, dstx, dsty, width, height, opcode, 1); - else - do_blit(dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0); - } else { - do_blit(dstri, Bpp, dstx, dsty, dstx, dsty, width, height, opcode, 0); - } - P96TRACE(("Did do_blit 1 in BlitRect()\n")); - } else { - P96TRACE(("Did not do_blit 1 in BlitRect()\n")); - } - } - return 1; } @@ -2719,8 +2384,6 @@ uae_u32 REGPARAM2 picasso_BlitRect (struct regstruct *regs) uae_u8 Mask = (uae_u8)m68k_dreg (regs, 6); uae_u32 result = 0; - P96_SM_RW; - P96TRACE(("BlitRect(%d, %d, %d, %d, %d, %d, 0x%x)\n", srcx, srcy, dstx, dsty, width, height, Mask)); result = BlitRect(renderinfo, (uaecptr)NULL, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC); @@ -2759,8 +2422,6 @@ uae_u32 REGPARAM2 picasso_BlitRectNoMaskComplete (struct regstruct *regs) uae_u32 RGBFmt = m68k_dreg (regs, 7); uae_u32 result = 0; - P96_SM_RW; - P96TRACE(("BlitRectNoMaskComplete() op 0x%02x, %08x:(%4d,%4d) --> %08x:(%4d,%4d), wh(%4d,%4d)\n", OpCode, get_long (srcri + PSSO_RenderInfo_Memory), srcx, srcy, get_long (dstri + PSSO_RenderInfo_Memory), dstx, dsty, width, height)); @@ -2835,8 +2496,6 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs) unsigned long ysize_mask; uae_u32 result = 0; - P96_SM_RW; - if(CopyRenderInfoStructureA2U (rinf, &ri) && CopyPatternStructureA2U (pinf, &pattern)) { Bpp = GetBytesPerPixel(ri.RGBFormat); uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset with address */ @@ -2956,11 +2615,6 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs) } } } - - /* If we need to update a second-buffer (extra_mem is set), then do it only if visible! */ - if (vsyncgfxwrite == 0 && picasso_vidinfo.extra_mem && renderinfo_is_current_screen (&ri)) - do_blit(&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0); - result = 1; } } @@ -3005,8 +2659,6 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) uae_u8 *tmpl_base; uae_u32 result = 0; - P96_SM_RW; - if (CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp)) { Bpp = GetBytesPerPixel(ri.RGBFormat); uae_mem = ri.Memory + Y*ri.BytesPerRow + X*Bpp; /* offset into address */ @@ -3140,11 +2792,6 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) } } } - - /* If we need to update a second-buffer (extra_mem is set), then do it only if visible! */ - if(vsyncgfxwrite == 0 && picasso_vidinfo.extra_mem && renderinfo_is_current_screen(&ri)) - do_blit(&ri, Bpp, X, Y, X, Y, W, H, BLIT_SRC, 0); - result = 1; } } @@ -3322,8 +2969,6 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs) struct BitMap local_bm; uae_u32 result = 0; - P96_SM_RW; - if (minterm != 0x0C) { write_log ("ERROR - BlitPlanar2Chunky() has minterm 0x%x, which I don't handle. Using fall-back routine.\n", minterm); @@ -3332,8 +2977,6 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Chunky (struct regstruct *regs) srcx, srcy, dstx, dsty, width, height, minterm, mask, local_bm.Depth)); P96TRACE(("P2C - BitMap has %d BPR, %d rows\n", local_bm.BytesPerRow, local_bm.Rows)); PlanarToChunky (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, mask); - if (vsyncgfxwrite == 0 && renderinfo_is_current_screen (&local_ri)) - do_blit(&local_ri, GetBytesPerPixel(local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0); result = 1; } @@ -3465,8 +3108,6 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs) struct ColorIndexMapping local_cim; uae_u32 result = 0; - P96_SM_RW; - if (minterm != 0x0C) { write_log ("WARNING - BlitPlanar2Direct() has unhandled op-code 0x%x. Using fall-back routine.\n", minterm); @@ -3479,8 +3120,6 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs) P96TRACE(("BlitPlanar2Direct(%d, %d, %d, %d, %d, %d) Minterm 0x%x, Mask 0x%x, Depth %d\n", srcx, srcy, dstx, dsty, width, height, minterm, Mask, local_bm.Depth)); PlanarToDirect (&local_ri, &local_bm, srcx, srcy, dstx, dsty, width, height, Mask, &local_cim); - if (vsyncgfxwrite == 0 && renderinfo_is_current_screen (&local_ri)) - do_blit(&local_ri, GetBytesPerPixel(local_ri.RGBFormat), dstx, dsty, dstx, dsty, width, height, BLIT_SRC, 0); result = 1; } return result; @@ -3660,333 +3299,15 @@ static void flushpixels_x (void) } -/* @@@ - Work to be done here! -* -* The address is the offset into our Picasso96 frame-buffer (pointed to by gfxmem_start) -* where the value was put. -* -* Porting work: on some machines you may not need these functions, ie. if the memory for the -* Picasso96 frame-buffer is directly viewable or directly blittable. On Win32 with DirectX, -* this is not the case. So I provide some write-through functions (as per Mathias' orders!) -*/ -#ifdef PIXEL_LOCK - -static int pixelcount; - -struct pixel32 { - uaecptr addr; - uae_u32 value; - int size; -}; -static struct pixel32 pixelbase[MAXFLUSHPIXEL + 2]; - -static void flushpixels_paletted(uae_u8 *dst) -{ - int psiz = GetBytesPerPixel (picasso_vidinfo.rgbformat); - int i; - - if (picasso96_state.RGBFormat != RGBFB_CHUNKY) - { - write_log ("ERROR - flushpixels() has non RGBFB_CHUNKY mode!\n"); - return; - } - if (!picasso_vidinfo.extra_mem) - return; - - for (i = 0; i < pixelcount; i++) - { - uaecptr addr = pixelbase[i].addr; - uae_u32 value = pixelbase[i].value; - int y = addr / picasso96_state.BytesPerRow; - int xbytes = addr % picasso96_state.BytesPerRow; - - if (xbytes < picasso96_state.Width * picasso96_state.BytesPerPixel && y < picasso96_state.Height) - { - if(psiz == 4) - { - uae_u8 *addr = dst + y * picasso_vidinfo.rowbytes + xbytes * 4; - switch (pixelbase[i].size) - { - case 4: - { - *(uae_u32 *)addr = picasso_vidinfo.clut[value & 0xff]; - addr += 4; - *(uae_u32 *)addr = picasso_vidinfo.clut[(value >> 8) & 0xff]; - addr += 4; - *(uae_u32 *)addr = picasso_vidinfo.clut[(value >> 16) & 0xff]; - addr += 4; - *(uae_u32 *)addr = picasso_vidinfo.clut[(value >> 24) & 0xff]; - break; - } - case 2: - { - *(uae_u32 *)addr = picasso_vidinfo.clut[(value >> 8) & 0xff]; - addr += 4; - *(uae_u32 *)addr = picasso_vidinfo.clut[value & 0xff]; - break; - } - case 1: - { - *(uae_u32 *)addr = picasso_vidinfo.clut[value & 0xff]; - break; - } - } - } - else - { - uae_u8 *addr = dst + y * picasso_vidinfo.rowbytes + xbytes * 2; - - switch (pixelbase[i].size) - { - case 4: - { - *(uae_u16 *)addr = picasso_vidinfo.clut[value & 0xff]; - addr += 2; - *(uae_u16 *)addr = picasso_vidinfo.clut[(value >> 8) & 0xff]; - addr += 2; - *(uae_u16 *)addr = picasso_vidinfo.clut[(value >> 16) & 0xff]; - addr += 2; - *(uae_u16 *)addr = picasso_vidinfo.clut[(value >> 24) & 0xff]; - break; - } - case 2: - { - *(uae_u16 *)addr = picasso_vidinfo.clut[(value >> 8) & 0xff]; - addr += 2; - *(uae_u16 *)addr = picasso_vidinfo.clut[value & 0xff]; - break; - } - case 1: - { - *(uae_u16 *)addr = picasso_vidinfo.clut[value & 0xff]; - break; - } - } - } - } - } -} - -static void flushpixels_rgb(uae_u8 *dst) -{ - uaecptr xminaddr = 0, xmaxaddr = 0; - uae_u8 *ydestaddr; - int i; - int rowwidth_src = picasso_vidinfo.width * picasso_vidinfo.pixbytes; - int rowwidth_dst = picasso96_state.Width * picasso96_state.BytesPerPixel; - - if (!picasso_vidinfo.extra_mem) - return; - - for (i = 0; i < pixelcount; i++) - { - uaecptr addr = pixelbase[i].addr; - uae_u32 value = pixelbase[i].value; - if(addr > xminaddr && addr < xmaxaddr) - { - switch (pixelbase[i].size) - { - case 4: - #ifdef SWAPSPEEDUP - *(uae_u32 *)(ydestaddr + addr) = value; - #else - do_put_mem_long ((uae_u32 *)(ydestaddr + addr), value); - #endif - break;; - case 2: - do_put_mem_word ((uae_u16 *)(ydestaddr + addr), value); - break; - case 1: - *(uae_u8 *)(ydestaddr + addr) = value; - break; - } - } - else - { - int xbytes, y; - y = addr / picasso96_state.BytesPerRow; - xbytes = addr % picasso96_state.BytesPerRow; - xminaddr = y * picasso96_state.BytesPerRow; - xmaxaddr = xminaddr + rowwidth_src; - ydestaddr = dst + y * picasso_vidinfo.rowbytes - xminaddr; - - if (xbytes < rowwidth_dst && y < picasso96_state.Height) - { - switch (pixelbase[i].size) - { - case 4: - #ifdef SWAPSPEEDUP - *(uae_u32 *)(ydestaddr + addr) = value; - #else - do_put_mem_long ((uae_u32 *)(ydestaddr + addr), value); - #endif - break;; - case 2: - do_put_mem_word ((uae_u16 *)(ydestaddr + addr), value); - break; - case 1: - *(uae_u8 *)(ydestaddr + addr) = value; - break; - } - } - else - { - xmaxaddr = 0; - } - } - } -} - static void flushpixels(void) { - uae_u8 *dst; - int lock = 0; - static int cnt; - - if (!picasso_on) { - pixelcount = 0; - return; - } - if (p96mode) { - flushpixels_x (); - return; - } - if (pixelcount == 0) - return; -#ifndef _DEBUG - if(DirectDraw_IsLocked() == FALSE) { - dst = gfx_lock_picasso (); - lock = 1; - } else -#endif - dst = picasso96_state.HostAddress; - if (dst) { - DX_Invalidate (-1, -1, -1, -1); - if(picasso_vidinfo.rgbformat == picasso96_state.RGBFormat) - flushpixels_rgb(dst); - else - flushpixels_paletted(dst); - } - if(lock) - gfx_unlock_picasso(); - pixelcount = 0; + flushpixels_x (); } -#endif - static void flushpixels_lock (void) { flushpixels(); } -STATIC_INLINE void write_gfx_x (uaecptr addr, uae_u32 value, int size) -{ -#ifndef PIXEL_LOCK - int y; - uaecptr oldaddr = addr; -#ifdef LOCK_UNLOCK_MADNESS - int x, xbytes; - uae_u8 *dst; -#endif -#endif - - if (!picasso_on) - return; - -#ifdef PIXEL_LOCK - addr += gfxmem_start; - /* Check to see if this needs to be written through to the display, or was it an "offscreen" area? */ - if (addr >= picasso96_state.Address && addr + size < picasso96_state.Extent) { - addr -= picasso96_state.XYOffset; - if (pixelcount > MAXFLUSHPIXEL) - flushpixels(); - pixelbase[pixelcount].addr = addr; - pixelbase[pixelcount].value = value; - pixelbase[pixelcount++].size = size; - } - return; -#endif -} - -static uae_u32 REGPARAM2 gfxmem_lget (uaecptr addr) -{ - uae_u32 *m; - - P96_SM_R; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u32 *)(gfxmemory + addr); - return do_get_mem_long(m); -} - -static uae_u32 REGPARAM2 gfxmem_wget (uaecptr addr) -{ - uae_u16 *m; - P96_SM_R; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u16 *)(gfxmemory + addr); - return do_get_mem_word(m); -} - -static uae_u32 REGPARAM2 gfxmem_bget (uaecptr addr) -{ - P96_SM_R; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - return gfxmemory[addr]; -} - -static void REGPARAM2 gfxmem_lput (uaecptr addr, uae_u32 l) -{ - uae_u32 *m; -#ifdef SWAPSPEEDUP - __asm { //byteswap now - mov eax,l - bswap eax - mov l,eax - } -#endif - P96_SM_W; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u32 *)(gfxmemory + addr); -#ifdef SWAPSPEEDUP - *m = l; -#else - do_put_mem_long(m, l); -#endif - /* write the long-word to our displayable memory */ - if (vsyncgfxwrite == 0) - write_gfx_x(addr, l, 4); -} - -static void REGPARAM2 gfxmem_wput (uaecptr addr, uae_u32 w) -{ - uae_u16 *m; - P96_SM_W; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - m = (uae_u16 *)(gfxmemory + addr); - do_put_mem_word(m, (uae_u16)w); - - /* write the word to our displayable memory */ - if (vsyncgfxwrite == 0) - write_gfx_x(addr, w, 2); -} - -static void REGPARAM2 gfxmem_bput (uaecptr addr, uae_u32 b) -{ - P96_SM_W; - addr -= gfxmem_start & gfxmem_mask; - addr &= gfxmem_mask; - gfxmemory[addr] = b; - - /* write the byte to our displayable memory */ - if (vsyncgfxwrite == 0) - write_gfx_x(addr, b, 1); -} - - static uae_u32 REGPARAM2 gfxmem_lgetx (uaecptr addr) { uae_u32 *m; @@ -4052,13 +3373,6 @@ static uae_u8 *REGPARAM2 gfxmem_xlate (uaecptr addr) return gfxmemory + addr; } -addrbank gfxmem_bank = { - gfxmem_lget, gfxmem_wget, gfxmem_bget, - gfxmem_lput, gfxmem_wput, gfxmem_bput, - gfxmem_xlate, gfxmem_check, NULL, "RTG RAM (Indirect)", - dummy_lgeti, dummy_wgeti, ABFLAG_RAM -}; - addrbank gfxmem_bankx = { gfxmem_lgetx, gfxmem_wgetx, gfxmem_bgetx, gfxmem_lputx, gfxmem_wputx, gfxmem_bputx, @@ -4074,10 +3388,9 @@ void InitPicasso96 (void) int i; have_done_picasso = 0; - pixelcount = 0; palette_changed = 0; //fastscreen - oldscr=0; + oldscr = 0; //fastscreen memset (&picasso96_state, 0, sizeof(struct picasso96_state_struct)); diff --git a/od-win32/picasso96_win.h b/od-win32/picasso96_win.h index 03ff6148..9e364395 100755 --- a/od-win32/picasso96_win.h +++ b/od-win32/picasso96_win.h @@ -12,17 +12,6 @@ #include "dxwrap.h" -#ifdef _DEBUG -void PICASSO96_Lock2(char *filename, int linenum); -#define PICASSO96_Lock() PICASSO96_Lock2(__FILE__, __LINE__) - -void PICASSO96_Unlock2(char *filename, int linenum); -#define PICASSO96_Unlock() PICASSO96_Unlock2(__FILE__, __LINE__) -#endif - -#define PIC_READ (S_READ) -#define PIC_WRITE (S_WRITE) - #define NOSIGNAL 0xFFFFFFFF /************************************************************************/ @@ -515,8 +504,6 @@ extern void DX_SetPalette (int start, int count); extern int DX_BitsPerCannon (void); extern void DX_Invalidate (int, int, int, int); extern int DX_Flip(void); -extern int DX_Blit(int srcx, int srcy, int dstx, int dsty, int w, int h, BLIT_OPCODE opcode); -extern int DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE rgbtype); extern void picasso_enablescreen (int on); extern void picasso_refresh (void); extern void picasso_handle_vsync (void); @@ -550,7 +537,6 @@ extern void picasso_clearcursor (void); extern int p96refresh_active; extern int p96hsync_counter; -extern int p96mode; #endif diff --git a/od-win32/resources/resource.h b/od-win32/resources/resource.h index ebdbbe88..31e8d746 100755 --- a/od-win32/resources/resource.h +++ b/od-win32/resources/resource.h @@ -322,7 +322,6 @@ #define IDC_PORT1_JOYS 1027 #define IDC_SCREENMODE_RTG 1027 #define IDC_MBMEM1 1028 -#define IDC_P96MODE 1029 #define IDC_SLOWMEM 1030 #define IDC_MBMEM2 1031 #define IDC_PARALLEL 1033 @@ -637,7 +636,7 @@ #define IDC_DF3TYPE 1598 #define IDC_SOUNDSPEEDTEXT 1599 #define IDC_SOUNDSPEEDCAPTION 1600 -#define IDC_NOOVERLAY 1601 +#define IDC_RTGMATCHDEPTH 1601 #define IDC_ROMFILE2TEXT 1602 #define IDC_ROMTEXT 1603 #define IDC_KEYTEXT 1604 @@ -850,7 +849,6 @@ #define IDC_CS_KSMIRROR_E0 1716 #define IDC_STRINGBOXEDIT 1716 #define IDC_CS_CD32CD 1717 -#define IDC_STRINGBOX_TEXT 1717 #define IDC_CS_CD32C2P 1718 #define IDC_CS_CD32NVRAM 1719 #define IDC_CS_CDTVCD 1720 @@ -968,6 +966,7 @@ #define ID_DBG_COPYLB 40041 #define ID_DBG_TOGGLEBP 40042 #define ID_DBG_DELETEBPS 40043 +#define ID_DBG_SETTOPC 40044 // Next default values for new objects // @@ -976,7 +975,7 @@ #define _APS_NO_MFC 1 #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 336 -#define _APS_NEXT_COMMAND_VALUE 40044 +#define _APS_NEXT_COMMAND_VALUE 40045 #define _APS_NEXT_CONTROL_VALUE 1785 #define _APS_NEXT_SYMED_VALUE 101 #endif diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index 66482d05..7d4d3f24 100755 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -1,6 +1,6 @@ // Microsoft Visual C++ generated resource script. // -#include "resource." +#include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// @@ -145,7 +145,6 @@ BEGIN RTEXT "Motherboard RAM (High area):",-1,39,148,129,10,SS_CENTERIMAGE CONTROL "",IDC_MBMEM2,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,180,144,59,20 EDITTEXT IDC_MBRAM2,243,147,30,12,ES_CENTER | ES_READONLY - COMBOBOX IDC_P96MODE,80,74,52,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP END IDD_CPU DIALOGEX 0, 0, 300, 226 @@ -402,7 +401,7 @@ BEGIN CONTROL "Don't show taskbar button",IDC_NOTASKBARBUTTON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,66,117,10 CONTROL "bsdsocket.library emulation",IDC_SOCKETS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,15,120,10 CONTROL "Use CTRL-F11 to quit",IDC_CTRLF11,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,27,120,10 - CONTROL "Don't use RGB overlays",IDC_NOOVERLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,40,120,10 + CONTROL "RTG color depth matching [] Do not use color space conversion if possible.",IDC_RTGMATCHDEPTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,40,120,10 CONTROL "Synchronize clock",IDC_CLOCKSYNC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,161,53,115,10 GROUPBOX "Keyboard LEDs",IDC_STATIC,7,140,85,94 COMBOBOX IDC_KBLED1,22,154,56,65,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP @@ -843,11 +842,10 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,48,39,50,14 PUSHBUTTON "Cancel",IDCANCEL,151,39,50,14 EDITTEXT IDC_STRINGBOXEDIT,7,17,214,14,ES_AUTOHSCROLL | ES_WANTRETURN - CTEXT "Custom input event",IDC_STRINGBOX_TEXT,23,5,187,10,SS_CENTERIMAGE | WS_TABSTOP END IDD_DEBUGGER DIALOGEX 0, 0, 454, 368 -STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_THICKFRAME +STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_OVERLAPPEDWINDOW EXSTYLE WS_EX_CONTROLPARENT CAPTION "WinUAE Debugger" FONT 8, "Courier New", 0, 0, 0x0 @@ -876,7 +874,7 @@ BEGIN LISTBOX IDC_DBG_MCUSTOM,372,79,81,138,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT LISTBOX IDC_DBG_MISC,1,79,370,262,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL LISTBOX IDC_DBG_CUSTOM,1,79,370,262,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL - CONTROL "Auto set",IDC_DBG_AUTOSET,"Button",BS_AUTOCHECKBOX,84,79,50,12 + CONTROL "Auto set",IDC_DBG_AUTOSET,"Button",BS_AUTOCHECKBOX | NOT WS_TABSTOP,84,79,50,12 LISTBOX IDC_DBG_DASM2,1,79,370,87,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT LISTBOX IDC_DBG_MEM2,1,167,370,87,LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT END @@ -993,42 +991,54 @@ END IDM_DBGCONTEXTMENU MENU BEGIN + POPUP "Inactive" + BEGIN + POPUP "Copy" + BEGIN + MENUITEM "Copy line" ID_DBG_COPYLBLINE + MENUITEM "Copy all" ID_DBG_COPYLB + END + END POPUP "Memory" BEGIN POPUP "Copy" BEGIN - MENUITEM "Copy line", ID_DBG_COPYLBLINE - MENUITEM "Copy all", ID_DBG_COPYLB + MENUITEM "Copy line" ID_DBG_COPYLBLINE + MENUITEM "Copy all" ID_DBG_COPYLB END POPUP "Set top address" BEGIN - MENUITEM "Set to A0", ID_DBG_SETTOA0 - MENUITEM "Set to A1", ID_DBG_SETTOA1 - MENUITEM "Set to A2", ID_DBG_SETTOA2 - MENUITEM "Set to A3", ID_DBG_SETTOA3 - MENUITEM "Set to A4", ID_DBG_SETTOA4 - MENUITEM "Set to A5", ID_DBG_SETTOA5 - MENUITEM "Set to A6", ID_DBG_SETTOA6 - MENUITEM "Set to A7", ID_DBG_SETTOA7 - MENUITEM "Enter address", ID_DBG_ENTERADDR + MENUITEM "Set to A0", ID_DBG_SETTOA0 + MENUITEM "Set to A1", ID_DBG_SETTOA1 + MENUITEM "Set to A2", ID_DBG_SETTOA2 + MENUITEM "Set to A3", ID_DBG_SETTOA3 + MENUITEM "Set to A4", ID_DBG_SETTOA4 + MENUITEM "Set to A5", ID_DBG_SETTOA5 + MENUITEM "Set to A6", ID_DBG_SETTOA6 + MENUITEM "Set to A7", ID_DBG_SETTOA7 + MENUITEM "Enter address", ID_DBG_ENTERADDR END END POPUP "Disassembly" BEGIN POPUP "Copy" BEGIN - MENUITEM "Copy line", ID_DBG_COPYLBLINE - MENUITEM "Copy all", ID_DBG_COPYLB + MENUITEM "Copy line" ID_DBG_COPYLBLINE + MENUITEM "Copy all" ID_DBG_COPYLB END POPUP "Breakpoints" BEGIN - MENUITEM "Toggle breakpoint", ID_DBG_TOGGLEBP - MENUITEM "Clear all breakpoints", ID_DBG_DELETEBPS + MENUITEM "Toggle breakpoint" ID_DBG_TOGGLEBP + MENUITEM "Clear all breakpoints" ID_DBG_DELETEBPS + END + POPUP "Set top address" + BEGIN + MENUITEM "Set to PC" ID_DBG_SETTOPC + MENUITEM "Enter address", ID_DBG_ENTERADDR END END END - ///////////////////////////////////////////////////////////////////////////// // // WAVE @@ -1243,7 +1253,7 @@ BEGIN IDS_UNSUPPORTEDSCREENMODE_3 "the desktop is too small for the specified window size." IDS_UNSUPPORTEDSCREENMODE_4 - "you selected an RTG (Picasso96) display with a color depth different from that of the desktop and an overlay was unavailable." + "you selected an RTG (Picasso96) display with unsupported color depth." IDS_FLOPPYTYPE35DD "3.5"" DD" IDS_FLOPPYTYPE35HD "3.5"" HD" IDS_FLOPPYTYPE525SD "5.25"" SD" diff --git a/od-win32/win32.c b/od-win32/win32.c index f825c8ec..85677310 100755 --- a/od-win32/win32.c +++ b/od-win32/win32.c @@ -1885,7 +1885,6 @@ void target_default_options (struct uae_prefs *p, int type) p->win32_iconified_pause = 1; p->win32_inactive_nosound = 0; p->win32_inactive_pause = 0; - p->win32_no_overlay = os_vista ? 1 : 0; p->win32_ctrl_F11_is_quit = 0; p->win32_soundcard = 0; p->win32_active_priority = 1; @@ -1904,6 +1903,7 @@ void target_default_options (struct uae_prefs *p, int type) p->win32_powersavedisabled = 1; p->win32_outsidemouse = 0; p->sana2 = 0; + p->win32_rtgmatchdepth = 1; } if (type == 1 || type == 0) { p->win32_uaescsimode = get_aspi(p->win32_uaescsimode); @@ -1943,7 +1943,7 @@ void target_save_options (struct zfile *f, struct uae_prefs *p) cfgfile_target_dwrite (f, "ctrl_f11_is_quit=%s\n", p->win32_ctrl_F11_is_quit ? "true" : "false"); cfgfile_target_dwrite (f, "midiout_device=%d\n", p->win32_midioutdev ); cfgfile_target_dwrite (f, "midiin_device=%d\n", p->win32_midiindev ); - cfgfile_target_dwrite (f, "no_overlay=%s\n", p->win32_no_overlay ? "true" : "false" ); + cfgfile_target_dwrite (f, "rtg_match_depth=%s\n", p->win32_rtgmatchdepth ? "true" : "false" ); cfgfile_target_dwrite (f, "borderless=%s\n", p->win32_borderless ? "true" : "false" ); cfgfile_target_dwrite (f, "uaescsimode=%s\n", scsimode[p->win32_uaescsimode]); cfgfile_target_dwrite (f, "soundcard=%d\n", p->win32_soundcard ); @@ -2004,11 +2004,8 @@ int target_parse_option (struct uae_prefs *p, char *option, char *value) || cfgfile_intval (option, value, "kbledmode", &p->win32_kbledmode, 1) || cfgfile_intval (option, value, "cpu_idle", &p->cpu_idle, 1)); - if (cfgfile_yesno (option, value, "no_overlay", &p->win32_no_overlay)) { - if (os_vista) - p->win32_no_overlay = 1; + if (cfgfile_yesno (option, value, "rtg_match_depth", &p->win32_rtgmatchdepth)) return 1; - } if (cfgfile_yesno (option, value, "aspi", &v)) { p->win32_uaescsimode = 0; @@ -2487,7 +2484,6 @@ static void WIN32_HandleRegistryStuff(void) regclosetree (read_disk_history ()); read_rom_list (); load_keyring(NULL, NULL); - regqueryint (NULL, "p96mode", &p96mode); } #if WINUAEPUBLICBETA > 0 @@ -2692,11 +2688,8 @@ static int osdetect (void) if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) os_64bit = 1; } - if (!os_winnt) { - extern int p96mode; - p96mode = 0; - return 1; - } + if (!os_winnt) + return 0; os_winnt_admin = isadminpriv (); if (os_winnt_admin) { if (pIsUserAnAdmin) { diff --git a/od-win32/win32.h b/od-win32/win32.h index 2387d7e9..1b5b36bf 100755 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -15,9 +15,9 @@ #define GETBDM(x) (((x) - ((x / 10000) * 10000)) / 100) #define GETBDD(x) ((x) % 100) -#define WINUAEBETA 4 +#define WINUAEBETA 5 #define WINUAEPUBLICBETA 1 -#define WINUAEDATE MAKEBD(2008, 2, 25) +#define WINUAEDATE MAKEBD(2008, 3, 1) #define WINUAEEXTRA "" #define WINUAEREV "" diff --git a/od-win32/win32_scale2x.c b/od-win32/win32_scale2x.c index 4f1b8f73..2036fec2 100755 --- a/od-win32/win32_scale2x.c +++ b/od-win32/win32_scale2x.c @@ -39,7 +39,7 @@ struct uae_filter uaefilters[] = static int dst_width, dst_height, amiga_width, amiga_height, amiga_depth, dst_depth, scale; uae_u8 *bufmem_ptr; -static int tempsurf; +static LPDIRECTDRAWSURFACE7 tempsurf; static uae_u8 *tempsurf2, *tempsurf3; void S2X_configure (int rb, int gb, int bb, int rs, int gs, int bs) @@ -52,8 +52,8 @@ void S2X_configure (int rb, int gb, int bb, int rs, int gs, int bs) void S2X_free (void) { - if (tempsurf) - IDirectDrawSurface7_Release (DirectDrawState.temporary.surface); + + freesurface (tempsurf); tempsurf = 0; xfree (tempsurf2); tempsurf2 = 0; @@ -64,7 +64,6 @@ void S2X_free (void) void S2X_init (int dw, int dh, int aw, int ah, int mult, int ad, int dd) { int flags = 0; - HRESULT ddrval; if (!currprefs.gfx_filter || !usedfilter) { usedfilter = &uaefilters[0]; @@ -85,23 +84,9 @@ void S2X_init (int dw, int dh, int aw, int ah, int mult, int ad, int dd) amiga_depth = ad; scale = mult; - tempsurf = 1; - ZeroMemory (&DirectDrawState.temporary.desc, sizeof (DDSURFACEDESC2)); - DirectDrawState.temporary.desc.dwSize = sizeof (DDSURFACEDESC2); - DirectDrawState.temporary.desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - DirectDrawState.temporary.desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; - DirectDrawState.temporary.desc.dwWidth = dst_width; - DirectDrawState.temporary.desc.dwHeight = dst_height; - if (DirectDraw_GetPrimaryPixelFormat (&DirectDrawState.temporary.desc.ddpfPixelFormat)) - DirectDrawState.temporary.desc.dwFlags |= DDSD_PIXELFORMAT; - ddrval = IDirectDraw7_CreateSurface (DirectDrawState.directdraw.dd, - &DirectDrawState.temporary.desc, - &DirectDrawState.temporary.surface, - NULL); - if (FAILED(ddrval)) { - write_log ("DDRAW: failed to create temp surface\n%s\n", DXError (ddrval)); - tempsurf = 0; - } + tempsurf = allocsurface (dst_width, dst_height); + if (!tempsurf) + write_log ("DDRAW: failed to create temp surface\n"); if (usedfilter->type == UAE_FILTER_HQ) { int w = amiga_width > dst_width ? amiga_width : dst_width; @@ -210,7 +195,7 @@ void S2X_render (void) if (tempsurf && sr.left != 0 || sr.top != 0 || sr.right != dst_width || sr.bottom != dst_height || dr.top != 0 || dr.right != dst_width || dr.left != 0 || dr.bottom != dst_height || currprefs.gfx_filter_upscale) { - dds = DirectDrawState.temporary.surface; + dds = tempsurf; temp_needed = 1; } } @@ -231,7 +216,7 @@ void S2X_render (void) dptr = (uae_u8*)desc.lpSurface; pitch = desc.lPitch; } else { - if (!DirectDraw_SurfaceLock (lockable_surface)) + if (!DirectDraw_SurfaceLock ()) return; dptr = DirectDraw_GetSurfacePointer (); pitch = DirectDraw_GetSurfacePitch (); @@ -339,7 +324,7 @@ void S2X_render (void) end: if (temp_needed) { IDirectDrawSurface7_Unlock (dds, NULL); - DirectDraw_Blt (DirectDraw_GetLockableType(), &dr, temporary_surface, &sr, 0, NULL); + //DirectDraw_Blt (DirectDraw_GetLockableType(), &dr, temporary_surface, &sr, 0); } else { DirectDraw_SurfaceUnlock (); } @@ -350,7 +335,7 @@ void S2X_refresh (void) int y, pitch; uae_u8 *dptr; - if (!DirectDraw_SurfaceLock (lockable_surface)) + if (!DirectDraw_SurfaceLock ()) return; dptr = DirectDraw_GetSurfacePointer (); pitch = DirectDraw_GetSurfacePitch(); diff --git a/od-win32/win32gfx.c b/od-win32/win32gfx.c index 40bdb40c..e5298d9f 100755 --- a/od-win32/win32gfx.c +++ b/od-win32/win32gfx.c @@ -56,7 +56,6 @@ #define DM_DX_FULLSCREEN 1 #define DM_W_FULLSCREEN 2 -#define DM_OVERLAY 4 #define DM_OPENGL 8 #define DM_DX_DIRECT 16 #define DM_PICASSO96 32 @@ -66,18 +65,20 @@ #define DM_D3D_FULLSCREEN 512 #define DM_SWSCALE 1024 +#define SM_WINDOW 0 +#define SM_FULLSCREEN_DX 2 +#define SM_OPENGL_WINDOW 3 +#define SM_OPENGL_FULLWINDOW 9 +#define SM_OPENGL_FULLSCREEN_DX 4 +#define SM_D3D_WINDOW 5 +#define SM_D3D_FULLWINDOW 10 +#define SM_D3D_FULLSCREEN_DX 6 +#define SM_FULLWINDOW 7 +#define SM_NONE 11 + struct uae_filter *usedfilter; -struct winuae_modes { - int fallback; - char *name; - unsigned int aflags; - unsigned int pflags; -}; struct winuae_currentmode { - struct winuae_modes *mode; - struct winuae_modes *pmode[3]; - struct winuae_modes *amode[3]; unsigned int flags; int native_width, native_height, native_depth, pitch; int current_width, current_height, current_depth; @@ -85,13 +86,12 @@ struct winuae_currentmode { int frequency; int mapping_is_mainscreen; int initdone; - int modeindex; LPPALETTEENTRY pal; }; struct PicassoResolution *DisplayModes; struct MultiDisplay Displays[MAX_DISPLAYS]; -GUID *displayGUID; +static GUID *displayGUID; static struct winuae_currentmode currentmodestruct; static int screen_is_initialized; @@ -99,121 +99,7 @@ int display_change_requested, normal_display_change_starting; int window_led_drives, window_led_drives_end; extern int console_logging; -#define SM_WINDOW 0 -#define SM_WINDOW_OVERLAY 1 -#define SM_FULLSCREEN_DX 2 -#define SM_OPENGL_WINDOW 3 -#define SM_OPENGL_FULLWINDOW 9 -#define SM_OPENGL_FULLSCREEN_DX 4 -#define SM_D3D_WINDOW 5 -#define SM_D3D_FULLWINDOW 10 -#define SM_D3D_FULLSCREEN_DX 6 -#define SM_FULLWINDOW 7 -#define SM_FULLWINDOW_OVERLAY 8 -#define SM_NONE 11 - -static struct winuae_modes wmodes[] = -{ - { - 0, "Windowed", - DM_DDRAW, - DM_PICASSO96 | DM_DDRAW - }, - { - 0, "Windowed Overlay", - DM_OVERLAY | DM_DX_DIRECT | DM_DDRAW, - DM_OVERLAY | DM_DX_DIRECT | DM_DDRAW | DM_PICASSO96 - }, - { - 1, "Fullscreen", - DM_DX_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW, - DM_DX_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW | DM_PICASSO96 - }, - { - 1, "Windowed OpenGL", - DM_OPENGL | DM_DC, - 0 - }, - { - 3, "DirectDraw Fullscreen OpenGL", - DM_OPENGL | DM_DX_FULLSCREEN | DM_DC, - 0 - }, - { - 0, "Windowed Direct3D", - DM_D3D, - 0 - }, - { - 0, "Fullscreen Direct3D", - DM_D3D | DM_D3D_FULLSCREEN, - 0 - }, - { - 1, "Fullwindow", - DM_W_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW, - DM_W_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW | DM_PICASSO96 - }, - { - 1, "Fullwindow overlay", - DM_OVERLAY | DM_W_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW, - DM_OVERLAY | DM_W_FULLSCREEN | DM_DX_DIRECT | DM_DDRAW | DM_PICASSO96 - }, - { - 1, "Fullwindow OpenGL", - DM_W_FULLSCREEN | DM_OPENGL | DM_DX_DIRECT, - 0 - }, - { - 0, "Fullwindow Direct3D", - DM_W_FULLSCREEN | DM_D3D, - 0 - }, - { - 0, "none", - 0, - 0 - } -}; - static struct winuae_currentmode *currentmode = ¤tmodestruct; -static int gfx_tempbitmap; - -static int modefallback (unsigned int mask) -{ - if (mask == DM_OVERLAY) { - if (currentmode->amode[0] == &wmodes[SM_WINDOW_OVERLAY]) - currentmode->amode[0] = &wmodes[0]; - if (currentmode->pmode[0] == &wmodes[SM_WINDOW_OVERLAY]) - currentmode->pmode[0] = &wmodes[0]; - return 1; - } - if (!picasso_on) { - if (currprefs.gfx_afullscreen) { - currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen = 0; - updatewinfsmode (&currprefs); - return 1; - } else { - if (currentmode->amode[0] == &wmodes[0]) - return 0; - currentmode->amode[0] = &wmodes[0]; - return 1; - } - } else { - if (currprefs.gfx_pfullscreen) { - currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen = 0; - return 1; - } else { - if (currentmode->pmode[0] == &wmodes[0]) { - currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen = 1; - return 1; - } - currentmode->pmode[0] = &wmodes[0]; - return 1; - } - } - return 0; -} int screen_is_picasso = 0; @@ -263,28 +149,106 @@ int WIN32GFX_GetDepth (int real) return real ? currentmode->native_depth : currentmode->current_depth; } -int WIN32GFX_GetWidth(void) +int WIN32GFX_GetWidth (void) { return currentmode->current_width; } -int WIN32GFX_GetHeight(void) +int WIN32GFX_GetHeight (void) { return currentmode->current_height; } -#include "dxwrap.h" - static BOOL doInit (void); uae_u32 default_freq = 0; HWND hStatusWnd = NULL; -HINSTANCE hDDraw = NULL; uae_u16 picasso96_pixel_format = RGBFF_CHUNKY; static char scrlinebuf[4096 * 4]; /* this is too large, but let's rather play on the safe side here */ + +static COLORREF BuildColorRef(uae_u32 color) +{ + COLORREF result; + if(DirectDraw_GetCurrentDepth () <= 8) + result = color; + else + result = color; + return result; +} + +void centerdstrect (RECT *dr, RECT *sr) +{ + if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_W_FULLSCREEN))) + OffsetRect(dr, amigawin_rect.left, amigawin_rect.top); + if (currentmode->flags & DM_W_FULLSCREEN) { + int dx, dy; + OffsetRect (dr, (currentmode->native_width - currentmode->current_width) / 2, + (currentmode->native_height - currentmode->current_height) / 2); + dx = (dr->right - dr->left) - currentmode->current_width; + if (dx > 0) { + dr->right -= dx; + sr->right -= dx; + } + dy = (dr->bottom - dr->top) - currentmode->current_height; + if (dy > 0) { + dr->bottom -= dy; + sr->bottom -= dy; + } + } +} + + +int DX_Fill (int dstx, int dsty, int width, int height, uae_u32 color) +{ + int result = 0; + RECT dstrect; + RECT srcrect; + DDBLTFX ddbltfx; + + memset (&ddbltfx, 0, sizeof (ddbltfx)); + ddbltfx.dwFillColor = BuildColorRef (color); + ddbltfx.dwSize = sizeof (ddbltfx); + + /* Set up our source rectangle. This NEVER needs to be adjusted for windowed display, since the + * source is ALWAYS in an offscreen buffer, or we're in full-screen mode. */ + SetRect (&srcrect, dstx, dsty, dstx + width, dsty + height); + + /* Set up our destination rectangle, and adjust for blit to windowed display (if necessary ) */ + SetRect (&dstrect, dstx, dsty, dstx + width, dsty + height); + centerdstrect (&dstrect, &srcrect); +#if 0 + /* Render our fill to the visible (primary) surface */ + hr = DirectDraw_Blt(primary_surface, &dstrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); + if(SUCCEEDED(hr)) { + result = 1; + if(DirectDraw_GetLockableType() == secondary_surface) { + /* We've colour-filled the visible, but still need to colour-fill the offscreen */ + hr = DirectDraw_Blt(secondary_surface, &srcrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); + if (FAILED(hr)) { + write_log ("DX_Fill2(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr)); + result = 0; + } + + } + } else { + write_log ("DX_Fill(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr)); + } +#endif + return result; +} + +int DX_Blit (int x, int y, int w, int h) +{ + RECT r; + + SetRect (&r, x, y, x + w, y + h); + DirectDraw_BlitToPrimary (&r); + return 1; +} + static int rgbformat_bits (RGBFTYPE t) { unsigned long f = 1 << t; @@ -296,6 +260,7 @@ static int rgbformat_bits (RGBFTYPE t) : 0); } + static int set_ddraw (void) { HRESULT ddrval; @@ -303,93 +268,53 @@ static int set_ddraw (void) int width = currentmode->native_width; int height = currentmode->native_height; int freq = currentmode->frequency; - int dxfullscreen, wfullscreen, dd, overlay; + int dxfullscreen, wfullscreen, dd; dxfullscreen = (currentmode->flags & DM_DX_FULLSCREEN) ? TRUE : FALSE; wfullscreen = (currentmode->flags & DM_W_FULLSCREEN) ? TRUE : FALSE; dd = (currentmode->flags & DM_DDRAW) ? TRUE : FALSE; - overlay = (currentmode->flags & DM_OVERLAY) ? TRUE : FALSE; + DirectDraw_FreeMainSurface (); ddrval = DirectDraw_SetCooperativeLevel (hAmigaWnd, dxfullscreen); if (FAILED(ddrval)) goto oops; if (dxfullscreen) { - write_log ( "set_ddraw: Trying %dx%d, bits=%d, refreshrate=%d\n", width, height, bits, freq ); + write_log ("set_ddraw: Trying %dx%d, bits=%d, refreshrate=%d\n", width, height, bits, freq); ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); if (FAILED(ddrval)) { write_log ("set_ddraw: failed, trying without forced refresh rate\n"); ddrval = DirectDraw_SetDisplayMode (width, height, bits, 0); - if (FAILED(ddrval)) { - write_log ("set_ddraw: Couldn't SetDisplayMode()\n"); + if (FAILED(ddrval)) goto oops; - } - } - ddrval = DirectDraw_GetDisplayMode (); - if (FAILED(ddrval)) { - write_log ("set_ddraw: Couldn't GetDisplayMode()\n" ); - goto oops; } } if (dd) { ddrval = DirectDraw_CreateClipper (); - if (FAILED(ddrval)) { - write_log ("set_ddraw: No clipping support\n"); + if (FAILED(ddrval)) goto oops; - } - ddrval = DirectDraw_CreateSurface (width, height); + ddrval = DirectDraw_CreateMainSurface (width, height); if (FAILED(ddrval)) { write_log ("set_ddraw: Couldn't CreateSurface() for primary because %s.\n", DXError (ddrval)); goto oops; } - if (DirectDraw_GetPrimaryBitCount() != (unsigned)bits && overlay) { - ddrval = DirectDraw_CreateOverlaySurface (width, height, bits, 0); - if(FAILED(ddrval)) - { - write_log ("set_ddraw: Couldn't CreateOverlaySurface(%d,%d,%d) because %s.\n", width, height, bits, DXError (ddrval)); - goto oops2; - } - } else { - overlay = 0; - } - - DirectDraw_ClearSurfaces(); - - if (!DirectDraw_DetermineLocking (dxfullscreen)) - { - write_log ("set_ddraw: Couldn't determine locking.\n"); - goto oops; - } - ddrval = DirectDraw_SetClipper (hAmigaWnd); - - if (FAILED(ddrval)) { - write_log ("set_ddraw: Couldn't SetHWnd()\n"); + if (FAILED(ddrval)) goto oops; + if (DirectDraw_SurfaceLock()) { + currentmode->pitch = DirectDraw_GetSurfacePitch (); + DirectDraw_SurfaceUnlock (); } - - if (bits == 8) { - ddrval = DirectDraw_CreatePalette (currentmode->pal); - if (FAILED(ddrval)) - { - write_log ("set_ddraw: Couldn't CreatePalette()\n"); - goto oops; - } - } - currentmode->pitch = DirectDraw_GetSurfacePitch (); } write_log ("set_ddraw() called, and is %dx%d@%d-bytes\n", width, height, bits); return 1; - oops: - write_log ("set_ddraw(): DirectDraw initialization failed with\n%s\n", DXError (ddrval)); -oops2: return 0; } -static HRESULT CALLBACK modesCallback(LPDDSURFACEDESC2 modeDesc, LPVOID context) +static HRESULT CALLBACK modesCallback (LPDDSURFACEDESC2 modeDesc, LPVOID context) { RGBFTYPE colortype; int i, j, ct, depth; @@ -409,7 +334,7 @@ static HRESULT CALLBACK modesCallback(LPDDSURFACEDESC2 modeDesc, LPVOID context) depth = 3; else if (ct & RGBMASK_32BIT) depth = 4; - if (depth == 0) + if (depth == 0 || depth == 1) return DDENUMRET_OK; i = 0; while (DisplayModes[i].depth >= 0) { @@ -594,7 +519,7 @@ void sortdisplays (void) if (SUCCEEDED(DirectDraw_GetDisplayMode())) { int w = DirectDraw_CurrentWidth (); int h = DirectDraw_CurrentHeight (); - int b = DirectDraw_GetSurfaceBitCount (); + int b = DirectDraw_GetCurrentDepth (); write_log ("Desktop: W=%d H=%d B=%d. CXVS=%d CYVS=%d\n", w, h, b, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)); DirectDraw_EnumDisplayModes (DDEDM_REFRESHRATES , modesCallback); @@ -691,121 +616,7 @@ int WIN32GFX_AdjustScreenmode(uae_u32 *pwidth, uae_u32 *pheight, uae_u32 *ppixbi return index; } -void setoverlay(int quick) -{ - static RECT sr, dr; - RECT statusr; - POINT p = {0,0}; - int maxwidth, maxheight, w, h; - HMONITOR hm; - MONITORINFO mi; - - if (quick) { - if (!(currentmode->flags & DM_OVERLAY)) - return; - goto end; - } - - hm = MonitorFromWindow (hMainWnd, MONITOR_DEFAULTTONEAREST); - mi.cbSize = sizeof (mi); - if (!GetMonitorInfo (hm, &mi)) - return; - - GetClientRect (hMainWnd, &dr); - // adjust the dest-rect to avoid the status-bar - if (hStatusWnd) { - if (GetWindowRect (hStatusWnd, &statusr)) - dr.bottom = dr.bottom - ( statusr.bottom - statusr.top ); - } - - ClientToScreen(hMainWnd, &p); - if (!currprefs.win32_borderless) { - p.x += 2; - p.y += 2; - } - dr.left = p.x; - dr.top = p.y; - dr.right += p.x + 1; - dr.bottom += p.y + 1; - /* overlay's coordinates are relative to monitor's top/left-corner */ - dr.left -= mi.rcMonitor.left; - dr.top -= mi.rcMonitor.top; - dr.right -= mi.rcMonitor.left; - dr.bottom -= mi.rcMonitor.top; - - w = currentmode->native_width; - h = currentmode->native_height; - - sr.left = 0; - sr.top = 0; - sr.right = w; - sr.bottom = h; - - // Adjust our dst-rect to match the dimensions of our src-rect - if (dr.right - dr.left > sr.right - sr.left) - dr.right = dr.left + sr.right - sr.left; - if (dr.bottom - dr.top > sr.bottom - sr.top) - dr.bottom = dr.top + sr.bottom - sr.top; - - maxwidth = mi.rcMonitor.right - mi.rcMonitor.left; - if (dr.right > maxwidth) { - sr.right = w - (dr.right - maxwidth); - dr.right = maxwidth; - } - maxheight = mi.rcMonitor.bottom - mi.rcMonitor.top; - if (dr.bottom > maxheight) { - sr.bottom = h - (dr.bottom - maxheight); - dr.bottom = maxheight; - } - if (dr.left < 0) { - sr.left = -dr.left; - dr.left = 0; - } - if (dr.top < 0) { - sr.top = -dr.top; - dr.top = 0; - } -end: - DirectDraw_UpdateOverlay(sr, dr); -} - -// This function is only called for full-screen Amiga screen-modes, and simply flips -// the front and back buffers. Additionally, because the emulation is not always drawing -// complete frames, we also need to update the back-buffer with the new contents we just -// flipped to. Thus, after our flip, we blit. -static int DX_Flip(void) -{ - int result = 0; -#if 0 - static frame_time_t end; - frame_time_t start, used; - - start = read_processor_time(); - used = start - end; - if (used > 0 && used < vsynctime * 2) { - int pct = used * 100 / vsynctime; - write_log ("%d\n", pct); - if (pct < 95) - sleep_millis_busy (2 + (95 - pct) / 10); - } -#endif - result = DirectDraw_Flip(0); - if (result) - { -// result = DirectDraw_BltFast(primary_surface, 0, 0, secondary_surface, NULL); -// result = DirectDraw_BltFast(primary_surface, 0, 0, tertiary_surface, NULL); -// result = DirectDraw_BltFast(secondary_surface, 0, 0, primary_surface, NULL); -// result = DirectDraw_BltFast(secondary_surface, 0, 0, tertiary_surface, NULL); - result = DirectDraw_BltFast(tertiary_surface, 0, 0, primary_surface, NULL); -// result = DirectDraw_BltFast(tertiary_surface, 0, 0, secondary_surface, NULL); - } -#if 0 - end = read_processor_time(); -#endif - return result; -} - -void flush_line( int lineno ) +void flush_line (int lineno) { } @@ -826,24 +637,16 @@ void flush_screen (int a, int b) #ifdef GFXFILTER } else if (currentmode->flags & DM_SWSCALE) { S2X_render (); - if (currentmode->flags & DM_DX_FULLSCREEN) - DX_Flip (); - else if (DirectDraw_GetLockableType() != overlay_surface) - DX_Blit (0, 0, 0, 0, WIN32GFX_GetWidth(), WIN32GFX_GetHeight(), BLIT_SRC); + DirectDraw_Flip (1); #endif - } else if ((currentmode->flags & DM_DDRAW) && DirectDraw_GetLockableType() == secondary_surface ) { - if (currentmode->flags & DM_DX_FULLSCREEN) { - if(turbo_emulation || DX_Flip() == 0) - DX_Blit (0, a, 0, a, currentmode->current_width, b - a + 1, BLIT_SRC); - } else if(DirectDraw_GetLockableType() != overlay_surface) - DX_Blit (0, a, 0, a, currentmode->current_width, b - a + 1, BLIT_SRC); + } else if (currentmode->flags & DM_DDRAW) { + DirectDraw_Flip (1); } - setoverlay(1); } static uae_u8 *ddraw_dolock (void) { - if (!DirectDraw_SurfaceLock(lockable_surface)) + if (!DirectDraw_SurfaceLock()) return 0; gfxvidinfo.bufmem = DirectDraw_GetSurfacePointer(); init_row_map (); @@ -878,7 +681,7 @@ void unlockscr (void) } else if (currentmode->flags & DM_SWSCALE) { return; } else if (currentmode->flags & DM_DDRAW) { - ddraw_unlockscr (); + DirectDraw_SurfaceUnlock (); } } @@ -903,10 +706,6 @@ uae_u8 *gfx_lock_picasso (void) return p; } -#define DX_INV 0 - -#if DX_INV == 0 - /* For the DX_Invalidate() and gfx_unlock_picasso() functions */ static int p96_double_buffer_firstx, p96_double_buffer_lastx; static int p96_double_buffer_first, p96_double_buffer_last; @@ -917,38 +716,25 @@ void gfx_unlock_picasso (void) DirectDraw_SurfaceUnlock(); if (p96_double_buffer_needs_flushing) { /* Here, our flush_block() will deal with a offscreen-plain (back-buffer) to visible-surface (front-buffer) */ - if (DirectDraw_GetLockableType() == secondary_surface) { - BOOL relock = FALSE; - if (DirectDraw_IsLocked()) { - relock = TRUE; - unlockscr(); - } - picasso_putcursor (p96_double_buffer_firstx, p96_double_buffer_first, - p96_double_buffer_lastx - p96_double_buffer_firstx + 1, p96_double_buffer_last - p96_double_buffer_first + 1); - DX_Blit (p96_double_buffer_firstx, p96_double_buffer_first, - p96_double_buffer_firstx, p96_double_buffer_first, - p96_double_buffer_lastx - p96_double_buffer_firstx + 1, - p96_double_buffer_last - p96_double_buffer_first + 1, - BLIT_SRC); - picasso_clearcursor (); - if (relock) { - lockscr(); - } + BOOL relock = FALSE; + if (DirectDraw_IsLocked()) { + relock = TRUE; + unlockscr(); + } + picasso_putcursor (p96_double_buffer_firstx, p96_double_buffer_first, + p96_double_buffer_lastx - p96_double_buffer_firstx + 1, p96_double_buffer_last - p96_double_buffer_first + 1); + DX_Blit (p96_double_buffer_firstx, p96_double_buffer_first, + p96_double_buffer_lastx - p96_double_buffer_firstx + 1, + p96_double_buffer_last - p96_double_buffer_first + 1); + picasso_clearcursor (); + if (relock) { + lockscr(); } p96_double_buffer_needs_flushing = 0; } } -#else - -void gfx_unlock_picasso (void) -{ - DirectDraw_SurfaceUnlock(); -} - -#endif - -static void close_hwnds( void ) +static void close_hwnds (void) { screen_is_initialized = 0; #ifdef AVIOUTPUT @@ -991,7 +777,7 @@ static int open_windows (void) in_sizemove = 0; updatewinfsmode (&currprefs); - if( !DirectDraw_Start(displayGUID) ) + if (!DirectDraw_Start (displayGUID)) return 0; write_log ("DirectDraw GUID=%s\n", outGUID (displayGUID)); @@ -1002,7 +788,6 @@ static int open_windows (void) if (screen_is_picasso) { currentmode->current_width = picasso96_state.Width; currentmode->current_height = picasso96_state.Height; - currentmode->current_depth = rgbformat_bits (picasso_vidinfo.selected_rgbformat); currentmode->frequency = abs (currprefs.gfx_refreshrate > default_freq ? currprefs.gfx_refreshrate : default_freq); } else { #endif @@ -1012,12 +797,15 @@ static int open_windows (void) #ifdef PICASSO96 } #endif - if (!screen_is_picasso || p96mode) { - currentmode->current_depth = (currprefs.color_mode == 0 ? 8 - : currprefs.color_mode == 1 ? 15 - : currprefs.color_mode == 2 ? 16 - : currprefs.color_mode == 3 ? 8 - : currprefs.color_mode == 4 ? 8 : 32); + currentmode->current_depth = (currprefs.color_mode == 0 ? 8 + : currprefs.color_mode == 1 ? 15 + : currprefs.color_mode == 2 ? 16 + : currprefs.color_mode == 3 ? 8 + : currprefs.color_mode == 4 ? 8 : 32); + if (screen_is_picasso && currprefs.win32_rtgmatchdepth && isfullscreen () > 0) { + int pbits = picasso96_state.BytesPerPixel * 8; + if (pbits >= 15) + currentmode->current_depth = pbits; } currentmode->amiga_width = currentmode->current_width; currentmode->amiga_height = currentmode->current_height; @@ -1038,20 +826,20 @@ int check_prefs_changed_gfx (void) { int c = 0; - c |= currprefs.gfx_size_fs.width != changed_prefs.gfx_size_fs.width ? (2|8) : 0; - c |= currprefs.gfx_size_fs.height != changed_prefs.gfx_size_fs.height ? (2|8) : 0; - c |= currprefs.gfx_size_win.width != changed_prefs.gfx_size_win.width ? (2|8) : 0; - c |= currprefs.gfx_size_win.height != changed_prefs.gfx_size_win.height ? (2|8) : 0; + c |= currprefs.gfx_size_fs.width != changed_prefs.gfx_size_fs.width ? 16 : 0; + c |= currprefs.gfx_size_fs.height != changed_prefs.gfx_size_fs.height ? 16 : 0; + c |= currprefs.gfx_size_win.width != changed_prefs.gfx_size_win.width ? 2 | 16 : 0; + c |= currprefs.gfx_size_win.height != changed_prefs.gfx_size_win.height ? 2 | 16 : 0; #if 0 c |= currprefs.gfx_size_win.x != changed_prefs.gfx_size_win.x ? 16 : 0; c |= currprefs.gfx_size_win.y != changed_prefs.gfx_size_win.y ? 16 : 0; #endif - c |= currprefs.color_mode != changed_prefs.color_mode ? (2|8) : 0; - c |= currprefs.gfx_afullscreen != changed_prefs.gfx_afullscreen ? (2|8) : 0; - c |= currprefs.gfx_pfullscreen != changed_prefs.gfx_pfullscreen ? (2|8) : 0; - c |= currprefs.gfx_avsync != changed_prefs.gfx_avsync ? (2|4|8) : 0; - c |= currprefs.gfx_pvsync != changed_prefs.gfx_pvsync ? (2|4|8) : 0; - c |= currprefs.gfx_refreshrate != changed_prefs.gfx_refreshrate ? (2|4|8) : 0; + c |= currprefs.color_mode != changed_prefs.color_mode ? 2 : 0; + c |= currprefs.gfx_afullscreen != changed_prefs.gfx_afullscreen ? 16 : 0; + c |= currprefs.gfx_pfullscreen != changed_prefs.gfx_pfullscreen ? 16 : 0; + c |= currprefs.gfx_avsync != changed_prefs.gfx_avsync ? 2 | 16 : 0; + c |= currprefs.gfx_pvsync != changed_prefs.gfx_pvsync ? 2 | 16 : 0; + c |= currprefs.gfx_refreshrate != changed_prefs.gfx_refreshrate ? 2 | 16 : 0; c |= currprefs.gfx_autoresolution != changed_prefs.gfx_autoresolution ? (2|8) : 0; c |= currprefs.gfx_filter != changed_prefs.gfx_filter ? (2|8) : 0; @@ -1076,7 +864,7 @@ int check_prefs_changed_gfx (void) c |= currprefs.gfx_display != changed_prefs.gfx_display ? (2|4|8) : 0; c |= currprefs.win32_alwaysontop != changed_prefs.win32_alwaysontop ? 1 : 0; c |= currprefs.win32_borderless != changed_prefs.win32_borderless ? 1 : 0; - c |= currprefs.win32_no_overlay != changed_prefs.win32_no_overlay ? 2 : 0; + c |= currprefs.win32_rtgmatchdepth != changed_prefs.win32_rtgmatchdepth ? 2 : 0; if (display_change_requested || c) { @@ -1084,21 +872,9 @@ int check_prefs_changed_gfx (void) if (display_change_requested) c |= 2; display_change_requested = 0; - fixup_prefs_dimensions (&changed_prefs); - currprefs.gfx_size_fs.width = changed_prefs.gfx_size_fs.width; - currprefs.gfx_size_fs.height = changed_prefs.gfx_size_fs.height; - currprefs.gfx_size_win.width = changed_prefs.gfx_size_win.width; - currprefs.gfx_size_win.height = changed_prefs.gfx_size_win.height; - currprefs.gfx_size_win.x = changed_prefs.gfx_size_win.x; - currprefs.gfx_size_win.y = changed_prefs.gfx_size_win.y; - currprefs.color_mode = changed_prefs.color_mode; - currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen; - currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen; - updatewinfsmode (&currprefs); - currprefs.gfx_avsync = changed_prefs.gfx_avsync; - currprefs.gfx_pvsync = changed_prefs.gfx_pvsync; - currprefs.gfx_refreshrate = changed_prefs.gfx_refreshrate; + currprefs.gfx_autoresolution = changed_prefs.gfx_autoresolution; + currprefs.color_mode = changed_prefs.color_mode; currprefs.gfx_filter = changed_prefs.gfx_filter; currprefs.gfx_filter_filtermode = changed_prefs.gfx_filter_filtermode; @@ -1122,9 +898,14 @@ int check_prefs_changed_gfx (void) currprefs.gfx_display = changed_prefs.gfx_display; currprefs.win32_alwaysontop = changed_prefs.win32_alwaysontop; currprefs.win32_borderless = changed_prefs.win32_borderless; - currprefs.win32_no_overlay = changed_prefs.win32_no_overlay; + currprefs.win32_rtgmatchdepth = changed_prefs.win32_rtgmatchdepth; inputdevice_unacquire (); + if (c & 16) { + extern int reopen (int); + if (reopen (c & 2)) + c |= 2; + } if (c & 2) { close_windows (); graphics_init (); @@ -1291,7 +1072,7 @@ static int get_color (int r, int g, int b, xcolnr * cnp) void init_colors (void) { - HRESULT ddrval; +// HRESULT ddrval; if (ncols256 == 0) { alloc_colors256 (get_color); @@ -1312,20 +1093,20 @@ void init_colors (void) { case 1: memcpy (xcolors, xcol8, sizeof xcolors); - ddrval = DirectDraw_SetPaletteEntries(0, 256, colors256); - if (FAILED(ddrval)) - write_log ("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval); + //ddrval = DirectDraw_SetPaletteEntries(0, 256, colors256); + //if (FAILED(ddrval)) + // write_log ("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval); break; case 2: case 3: case 4: - red_bits = bits_in_mask(DirectDraw_GetPixelFormatBitMask(red_mask)); - green_bits = bits_in_mask(DirectDraw_GetPixelFormatBitMask(green_mask)); - blue_bits = bits_in_mask(DirectDraw_GetPixelFormatBitMask(blue_mask)); - red_shift = mask_shift(DirectDraw_GetPixelFormatBitMask(red_mask)); - green_shift = mask_shift(DirectDraw_GetPixelFormatBitMask(green_mask)); - blue_shift = mask_shift(DirectDraw_GetPixelFormatBitMask(blue_mask)); + red_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (red_mask)); + green_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (green_mask)); + blue_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (blue_mask)); + red_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (red_mask)); + green_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (green_mask)); + blue_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (blue_mask)); alpha_bits = 0; alpha_shift = 0; break; @@ -1376,8 +1157,6 @@ void picasso_palette (void) void DX_SetPalette (int start, int count) { - HRESULT ddrval; - if (!screen_is_picasso) return; @@ -1385,22 +1164,20 @@ void DX_SetPalette (int start, int count) return; /* Set our DirectX palette here */ - if(currentmode->current_depth == 8) - { +#if 0 + if(currentmode->current_depth == 8) { + HRESULT ddrval; if (SUCCEEDED(DirectDraw_SetPalette(0))) { ddrval = DirectDraw_SetPaletteEntries(start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start])); if (FAILED(ddrval)) gui_message("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval); } - } - else - { + } else { write_log ("ERROR - DX_SetPalette() pixbytes %d\n", currentmode->current_depth >> 3); } +#endif } -#if DX_INV == 0 - void DX_Invalidate (int x, int y, int width, int height) { int last, lastx; @@ -1420,290 +1197,110 @@ void DX_Invalidate (int x, int y, int width, int height) p96_double_buffer_needs_flushing = 1; } -#else - -static void flashbox(int dstx, int dsty, int width, int height) -{ - int i; - HRESULT hr; - RECT dstrect; - RECT srcrect; - DDBLTFX ddbltfx; - memset(&ddbltfx, 0, sizeof(ddbltfx)); - ddbltfx.dwFillColor = 0x550055; - ddbltfx.dwSize = sizeof(ddbltfx); - - /* Set up our source rectangle. This NEVER needs to be adjusted for windowed display, since the - * source is ALWAYS in an offscreen buffer, or we're in full-screen mode. */ - SetRect(&srcrect, dstx, dsty, dstx+width, dsty+height); - - /* Set up our destination rectangle, and adjust for blit to windowed display (if necessary ) */ - SetRect(&dstrect, dstx, dsty, dstx+width, dsty+height); - if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_OVERLAY))) - OffsetRect(&dstrect, amigawin_rect.left, amigawin_rect.top); - - /* Render our fill to the visible (primary) surface */ - for (i = 0; i < 5; i++) { - hr = DirectDraw_Blt(primary_surface, &dstrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); - ddbltfx.dwFillColor = (i & 1) ? 0x550055 : 0xfffff00; - } - -} - -void DX_Invalidate (int x, int y, int width, int height) -{ - if (x < 0) { - x = 0; - y = 0; - width = currentmode->current_width; - height = currentmode->current_height; - } - if (DirectDraw_GetLockableType() == secondary_surface) { - BOOL relock = FALSE; - if (DirectDraw_IsLocked()) { - relock = TRUE; - unlockscr(); - } - flashbox (x, y, width, height); - DX_Blit (x, y, x, y, width, height, BLIT_SRC); - if (relock) { - lockscr(); - } - } -} - -#endif #endif -int DX_BitsPerCannon (void) +static void open_screen (void) { - return 8; + close_windows (); + open_windows (); +#ifdef PICASSO96 + DX_SetPalette (0, 256); +#endif } -static COLORREF BuildColorRef(int color, RGBFTYPE pixelformat) +static int ifs (struct uae_prefs *p) { - COLORREF result; - - /* Do special case first */ - if(pixelformat == RGBFB_CHUNKY) - result = color; + if (screen_is_picasso) + return p->gfx_pfullscreen == 1 ? 1 : (p->gfx_pfullscreen == 2 ? -1 : 0); else - result = do_get_mem_long(&color); - return result; -} - -static void centerrect(RECT *r) -{ - if(!(currentmode->flags & (DM_DX_FULLSCREEN | DM_OVERLAY | DM_W_FULLSCREEN))) - OffsetRect(r, amigawin_rect.left, amigawin_rect.top); - if (currentmode->flags & DM_W_FULLSCREEN) - OffsetRect(r, (currentmode->native_width - currentmode->current_width) / 2, - (currentmode->native_height - currentmode->current_height) / 2); + return p->gfx_afullscreen == 1 ? 1 : (p->gfx_afullscreen == 2 ? -1 : 0); } - -/* This is a general purpose DirectDrawSurface filling routine. It can fill within primary surface. - * Definitions: - * - primary is the displayed (visible) surface in VRAM, which may have an associated offscreen surface (or back-buffer) - */ -int DX_Fill(int dstx, int dsty, int width, int height, uae_u32 color, RGBFTYPE rgbtype) +static int reopen (int full) { - HRESULT hr; - int result = 0; - RECT dstrect; - RECT srcrect; - DDBLTFX ddbltfx; - memset(&ddbltfx, 0, sizeof(ddbltfx)); - ddbltfx.dwFillColor = BuildColorRef(color, rgbtype); - ddbltfx.dwSize = sizeof(ddbltfx); - - /* Set up our source rectangle. This NEVER needs to be adjusted for windowed display, since the - * source is ALWAYS in an offscreen buffer, or we're in full-screen mode. */ - SetRect(&srcrect, dstx, dsty, dstx + width, dsty + height); + int quick = 0; - /* Set up our destination rectangle, and adjust for blit to windowed display (if necessary ) */ - SetRect(&dstrect, dstx, dsty, dstx + width, dsty + height); - centerrect(&dstrect); - - /* Render our fill to the visible (primary) surface */ - hr = DirectDraw_Blt(primary_surface, &dstrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); - if(SUCCEEDED(hr)) { - result = 1; - if(DirectDraw_GetLockableType() == secondary_surface) { - /* We've colour-filled the visible, but still need to colour-fill the offscreen */ - hr = DirectDraw_Blt(secondary_surface, &srcrect, invalid_surface, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); - if (FAILED(hr)) { - write_log ("DX_Fill2(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr)); - result = 0; - } - - } - } else { - write_log ("DX_Fill(%dx%d %d%d): %s\n", dstx, dsty, width, height, DXError(hr)); - } - return result; -} - -/* This is a general purpose DirectDrawSurface blitting routine. It can blit within primary surface - * Definitions: - * - primary is the displayed (visible) surface in VRAM, which may have an associated offscreen surface (or back-buffer) - */ - -static DWORD BLIT_OPCODE_TRANSLATION[BLIT_LAST] = -{ - BLACKNESS, /* BLIT_FALSE */ - NOTSRCERASE,/* BLIT_NOR */ - -1, /* BLIT_ONLYDST NOT SUPPORTED */ - NOTSRCCOPY, /* BLIT_NOTSRC */ - SRCERASE, /* BLIT_ONLYSRC */ - DSTINVERT, /* BLIT_NOTDST */ - SRCINVERT, /* BLIT_EOR */ - -1, /* BLIT_NAND NOT SUPPORTED */ - SRCAND, /* BLIT_AND */ - -1, /* BLIT_NEOR NOT SUPPORTED */ - -1, /* NO-OP */ - MERGEPAINT, /* BLIT_NOTONLYSRC */ - SRCCOPY, /* BLIT_SRC */ - -1, /* BLIT_NOTONLYDST NOT SUPPORTED */ - SRCPAINT, /* BLIT_OR */ - WHITENESS /* BLIT_TRUE */ -}; - -int DX_Blit(int srcx, int srcy, int dstx, int dsty, int width, int height, BLIT_OPCODE opcode) -{ - HRESULT result; - RECT dstrect, srcrect; - DWORD dwROP = BLIT_OPCODE_TRANSLATION[opcode]; - DDBLTFX fx = { 0 }; - - if(dwROP == -1) { - /* Unsupported blit opcode! */ - return 0; - } - fx.dwSize = sizeof (fx); - fx.dwROP = dwROP; - - /* Set up our source rectangle. This NEVER needs to be adjusted for windowed display, since the - * source is ALWAYS in an offscreen buffer, or we're in full-screen mode. */ - SetRect(&srcrect, srcx, srcy, srcx + width, srcy + height); - - /* Set up our destination rectangle, and adjust for blit to windowed display (if necessary ) */ - SetRect(&dstrect, dstx, dsty, dstx + width, dsty + height); - - centerrect(&dstrect); + updatewinfsmode (&changed_prefs); - /* Render our blit within the primary surface */ - result = DirectDraw_Blt(primary_surface, &dstrect, DirectDraw_GetLockableType(), &srcrect, DDBLT_WAIT | DDBLT_ROP, &fx); - if (FAILED(result)) { - write_log ("DX_Blit1(%d,%d,%d,%d) failed: %s\n", srcx, srcy, width, height, DXError(result)); - return 0; - } else if(DirectDraw_GetLockableType() == secondary_surface) { - /* We've just blitted from the offscreen to the visible, but still need to blit from offscreen to offscreen - * NOTE: reset our destination rectangle again if its been modified above... */ - if((srcx != dstx) || (srcy != dsty)) { - SetRect(&dstrect, dstx, dsty, dstx + width, dsty + height); - result = DirectDraw_Blt(secondary_surface, &dstrect, secondary_surface, &srcrect, DDBLT_WAIT | DDBLT_ROP, &fx); - if (FAILED(result)) { - write_log ("DX_Blit2(%d,%d,%d,%d) failed: %s\n", srcx, srcy, width, height, DXError(result)); - } + if (changed_prefs.gfx_afullscreen != currprefs.gfx_afullscreen && !screen_is_picasso) + full = 1; + if (changed_prefs.gfx_pfullscreen != currprefs.gfx_pfullscreen && screen_is_picasso) + full = 1; + if (!screen_is_picasso && changed_prefs.gfx_afullscreen) { + if (currprefs.gfx_size_fs.width != changed_prefs.gfx_size_fs.width || + currprefs.gfx_size_fs.height != changed_prefs.gfx_size_fs.height) { + quick = 1; } } - return 1; -} - -void DX_WaitVerticalSync(void) -{ - DirectDraw_WaitForVerticalBlank (DDWAITVB_BLOCKBEGIN); -} -#if 0 -uae_u32 DX_ShowCursor(uae_u32 activate) -{ - uae_u32 result = 0; - if(ShowCursor(activate) > 0) - result = 1; - return result; -} -uae_u32 DX_MoveCursor(uae_u32 x, uae_u32 y) -{ - uae_u32 result = 0; + currprefs.gfx_size_fs.width = changed_prefs.gfx_size_fs.width; + currprefs.gfx_size_fs.height = changed_prefs.gfx_size_fs.height; + currprefs.gfx_size_win.width = changed_prefs.gfx_size_win.width; + currprefs.gfx_size_win.height = changed_prefs.gfx_size_win.height; + currprefs.gfx_size_win.x = changed_prefs.gfx_size_win.x; + currprefs.gfx_size_win.y = changed_prefs.gfx_size_win.y; + currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen; + currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen; + currprefs.gfx_avsync = changed_prefs.gfx_avsync; + currprefs.gfx_pvsync = changed_prefs.gfx_pvsync; + currprefs.gfx_refreshrate = changed_prefs.gfx_refreshrate; - // We may need to adjust the x,y values for our window-offset - if(!(currentmode->flags & DM_DX_FULLSCREEN)) - { - RECT rect; - if(GetWindowRect(hAmigaWnd, &rect)) - { - x = rect.left + x; - y = rect.top + y; - } - } - if(SetCursorPos(x, y)) - result = 1; - return result; -} -#endif -static void open_screen(void) -{ - close_windows (); - open_windows(); -#ifdef PICASSO96 - DX_SetPalette (0, 256); -#endif + + if (!quick) + return 1; + + open_windows (); + return 0; } #ifdef PICASSO96 static int modeswitchneeded (void) { - if (!p96mode) - return 1; - if (isfullscreen () >= 0) { + if (isfullscreen () > 0) { + if (picasso96_state.Width != currentmode->current_width || + picasso96_state.Height != currentmode->current_height) + return -1; + } else if (isfullscreen () == 0) { if (picasso96_state.Width != currentmode->current_width || picasso96_state.Height != currentmode->current_height) return 1; } else { if (picasso96_state.Width > currentmode->native_width || picasso96_state.Height > currentmode->native_height) - return 1; + return -1; } return 0; } -void gfx_set_picasso_state(int on) +void gfx_set_picasso_state (int on) { + int mode; if (screen_is_picasso == on) return; screen_is_picasso = on; - if (currprefs.gfx_afullscreen == currprefs.gfx_pfullscreen && !modeswitchneeded()) + mode = modeswitchneeded (); + currentmode->current_width = picasso96_state.Width; + currentmode->current_height = picasso96_state.Height; + picasso_vidinfo.width = picasso96_state.Width; + picasso_vidinfo.height = picasso96_state.Height; + if (currprefs.gfx_afullscreen != currprefs.gfx_pfullscreen) { + mode = 1; + } else if (!mode) { return; - open_screen(); + } + if (mode < 0) { + open_windows (); + } else { + open_screen (); + } } -void gfx_set_picasso_modeinfo(uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt) +void gfx_set_picasso_modeinfo (uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt) { - if (p96mode) { - if (screen_is_picasso && modeswitchneeded()) - open_screen (); - } else { - depth >>= 3; - if(((unsigned)picasso_vidinfo.width == w) && - ((unsigned)picasso_vidinfo.height == h) && - ((unsigned)picasso_vidinfo.depth == depth) && - (picasso_vidinfo.selected_rgbformat == rgbfmt)) - return; - - picasso_vidinfo.selected_rgbformat = rgbfmt; - picasso_vidinfo.width = w; - picasso_vidinfo.height = h; - picasso_vidinfo.depth = depth; - picasso_vidinfo.extra_mem = 1; - - if(screen_is_picasso && modeswitchneeded()) { - open_screen(); - } - } + if (screen_is_picasso && modeswitchneeded()) + open_screen (); } #endif @@ -1721,26 +1318,6 @@ static void gfxmode_reset (void) i++; } } -#endif - currentmode->amode[0] = &wmodes[currprefs.win32_no_overlay ? SM_WINDOW : SM_WINDOW_OVERLAY]; - currentmode->amode[1] = &wmodes[SM_FULLSCREEN_DX]; - currentmode->amode[2] = &wmodes[SM_FULLWINDOW]; - currentmode->pmode[0] = &wmodes[currprefs.win32_no_overlay ? SM_WINDOW : SM_WINDOW_OVERLAY]; - currentmode->pmode[1] = &wmodes[SM_FULLSCREEN_DX]; - currentmode->pmode[2] = &wmodes[SM_FULLWINDOW]; -#if defined (OPENGL) && defined (GFXFILTER) - if (usedfilter && usedfilter->type == UAE_FILTER_OPENGL) { - currentmode->amode[0] = &wmodes[SM_OPENGL_WINDOW]; - currentmode->amode[1] = &wmodes[SM_OPENGL_FULLSCREEN_DX]; - currentmode->amode[2] = &wmodes[SM_OPENGL_FULLWINDOW]; - } -#endif -#if defined (D3D) && defined (GFXFILTER) - if (usedfilter && usedfilter->type == UAE_FILTER_DIRECT3D) { - currentmode->amode[0] = &wmodes[SM_D3D_WINDOW]; - currentmode->amode[1] = &wmodes[SM_D3D_FULLSCREEN_DX]; - currentmode->amode[2] = &wmodes[SM_D3D_FULLWINDOW]; - } #endif } @@ -1791,7 +1368,7 @@ void graphics_leave (void) close_windows (); } -uae_u32 OSDEP_minimize_uae( void ) +uae_u32 OSDEP_minimize_uae (void) { return ShowWindow (hAmigaWnd, SW_MINIMIZE); } @@ -1809,7 +1386,7 @@ void close_windows (void) close_hwnds(); } -void WIN32GFX_ToggleFullScreen( void ) +void WIN32GFX_ToggleFullScreen (void) { display_change_requested = 1; if (screen_is_picasso) @@ -1913,10 +1490,13 @@ static int create_windows (void) int gap = 3; int x, y; + if (hAmigaWnd) { + write_log ("window already open\n"); + return 1; + } + if (fsw && !borderless) borderless = 1; - currentmode->native_width = currentmode->current_width; - currentmode->native_height = currentmode->current_height; window_led_drives = 0; window_led_drives_end = 0; hMainWnd = NULL; @@ -2040,7 +1620,6 @@ static int create_windows (void) return 0; } systray (NULL, TRUE); - //write_log ("notif: open_windows()\n"); systray (hAmigaWnd, FALSE); addnotifications (hAmigaWnd, FALSE); if (hMainWnd != hAmigaWnd) { @@ -2054,25 +1633,27 @@ static int create_windows (void) static void updatemodes (void) { - if (screen_is_picasso) { - currentmode->mode = currentmode->pmode[currprefs.gfx_pfullscreen]; - currentmode->flags = currentmode->mode->pflags; - } else { - currentmode->mode = currentmode->amode[currprefs.gfx_afullscreen]; - currentmode->flags = currentmode->mode->aflags; - } - currentmode->modeindex = currentmode->mode - &wmodes[0]; + DWORD flags; - currentmode->flags &= ~DM_SWSCALE; + flags = DM_DDRAW; + if (isfullscreen () > 0) + flags |= DM_DX_FULLSCREEN; + else if (isfullscreen () < 0) + flags |= DM_W_FULLSCREEN; #if defined (GFXFILTER) - if (usedfilter && !usedfilter->x[0]) { - currentmode->flags |= DM_SWSCALE; - if (currentmode->current_depth < 15) - currentmode->current_depth = 16; - } else if (!usedfilter && currentmode->current_depth >= 15) { - ;//currentmode->flags |= DM_SWSCALE; + if (usedfilter) { + if (!usedfilter->x[0]) { + flags |= DM_SWSCALE; + if (currentmode->current_depth < 15) + currentmode->current_depth = 16; + } + if (usedfilter->type == UAE_FILTER_DIRECT3D) + flags |= DM_D3D; + if (usedfilter->type == UAE_FILTER_OPENGL) + flags |= DM_OPENGL; } #endif + currentmode->flags = flags; } static BOOL doInit (void) @@ -2091,9 +1672,11 @@ static BOOL doInit (void) updatemodes (); currentmode->native_depth = 0; tmp_depth = currentmode->current_depth; + currentmode->native_width = currentmode->current_width; + currentmode->native_height = currentmode->current_height; write_log ("W=%d H=%d B=%d CT=%d\n", - DirectDraw_CurrentWidth (), DirectDraw_CurrentHeight (), DirectDraw_GetSurfaceBitCount (), colortype); + DirectDraw_CurrentWidth (), DirectDraw_CurrentHeight (), DirectDraw_GetCurrentDepth (), colortype); if (currentmode->current_depth < 15 && (currprefs.chipset_mask & CSMASK_AGA) && isfullscreen () > 0 && !WIN32GFX_IsPicassoScreen()) { static int warned; @@ -2106,36 +1689,22 @@ static BOOL doInit (void) warned = 1; } - if (!(currentmode->flags & DM_OVERLAY) && isfullscreen() <= 0 && !(currentmode->flags & (DM_OPENGL | DM_D3D))) { - write_log ("using desktop depth (%d -> %d) because not using overlay or opengl mode\n", - currentmode->current_depth, DirectDraw_GetSurfaceBitCount()); - currentmode->current_depth = DirectDraw_GetSurfaceBitCount(); + if (isfullscreen() <= 0 && !(currentmode->flags & (DM_OPENGL | DM_D3D))) { + currentmode->current_depth = DirectDraw_GetCurrentDepth (); updatemodes (); } - - //If screen depth is equal to the desired window_depth then no overlay is needed. - if (!(currentmode->flags & (DM_OPENGL | DM_D3D)) && DirectDraw_GetSurfaceBitCount() == currentmode->current_depth) { - write_log ("ignored overlay because desktop depth == requested depth (%d)\n", currentmode->current_depth); - modefallback (DM_OVERLAY); + if (!(currentmode->flags & (DM_OPENGL | DM_D3D)) && DirectDraw_GetCurrentDepth () == currentmode->current_depth) { updatemodes (); } if (colortype == RGBFB_NONE) { fs_warning = IDS_UNSUPPORTEDSCREENMODE_1; - } else if (colortype == RGBFB_CLUT && DirectDraw_GetSurfaceBitCount() != 8) { + } else if (colortype == RGBFB_CLUT && DirectDraw_GetCurrentDepth () != 8) { fs_warning = IDS_UNSUPPORTEDSCREENMODE_2; } else if (currentmode->current_width > GetSystemMetrics(SM_CXVIRTUALSCREEN) || currentmode->current_height > GetSystemMetrics(SM_CYVIRTUALSCREEN)) { if (!console_logging) fs_warning = IDS_UNSUPPORTEDSCREENMODE_3; -#ifdef PICASSO96 - } else if (screen_is_picasso && !p96mode && !currprefs.gfx_pfullscreen && - (picasso_vidinfo.selected_rgbformat != RGBFB_CHUNKY) && - (picasso_vidinfo.selected_rgbformat != colortype) && - !(currentmode->flags & DM_OVERLAY) ) - { - fs_warning = IDS_UNSUPPORTEDSCREENMODE_4; -#endif } if (fs_warning >= 0 && isfullscreen () <= 0) { char szMessage[MAX_DPATH], szMessage2[MAX_DPATH]; @@ -2162,13 +1731,8 @@ static BOOL doInit (void) #ifdef PICASSO96 if (screen_is_picasso) { currentmode->pal = (LPPALETTEENTRY) & picasso96_state.CLUT; - if (! set_ddraw ()) { - if (!modefallback (0)) - goto oops; - close_windows (); - if (!DirectDraw_Start (displayGUID)) - break; - continue; + if (!set_ddraw ()) { + goto oops; } picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch(); picasso_vidinfo.pixbytes = DirectDraw_GetBytesPerPixel(); @@ -2178,11 +1742,7 @@ static BOOL doInit (void) #endif currentmode->pal = colors256; if (! set_ddraw ()) { - if (!modefallback (0)) - goto oops; - close_windows (); - if (!DirectDraw_Start (displayGUID)) break; - continue; + goto oops; } currentmode->native_depth = currentmode->current_depth; #if defined (GFXFILTER) @@ -2234,33 +1794,18 @@ static BOOL doInit (void) } #ifdef PICASSO96 - if (p96mode) { - picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch(); - picasso_vidinfo.pixbytes = DirectDraw_GetBytesPerPixel(); - picasso_vidinfo.rgbformat = DirectDraw_GetPixelFormat(); - picasso_vidinfo.extra_mem = 1; - picasso_vidinfo.height = currentmode->current_height; - picasso_vidinfo.width = currentmode->current_width; - picasso_vidinfo.depth = currentmode->current_depth; - } + picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch(); + picasso_vidinfo.pixbytes = DirectDraw_GetBytesPerPixel(); + picasso_vidinfo.rgbformat = DirectDraw_GetPixelFormat(); + picasso_vidinfo.extra_mem = 1; + picasso_vidinfo.height = currentmode->current_height; + picasso_vidinfo.width = currentmode->current_width; + picasso_vidinfo.depth = currentmode->current_depth; #endif if ((currentmode->flags & DM_DDRAW) && !(currentmode->flags & (DM_D3D | DM_SWSCALE))) { - int flags; - if(!DirectDraw_SurfaceLock (lockable_surface)) - goto oops; - flags = DirectDraw_GetPixelFormatFlags(); - DirectDraw_SurfaceUnlock(); - if (flags & (DDPF_RGB | DDPF_PALETTEINDEXED8 | DDPF_RGBTOYUV)) { - write_log ("%s mode (bits: %d, pixbytes: %d)\n", currentmode->flags & DM_DX_FULLSCREEN ? "Full screen" : "Window", - DirectDraw_GetSurfaceBitCount(), currentmode->current_depth >> 3); - } else { - char szMessage[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_UNSUPPORTEDPIXELFORMAT, szMessage, MAX_DPATH); - gui_message(szMessage); - goto oops; - } + ; } else if (!(currentmode->flags & DM_SWSCALE)) { @@ -2285,9 +1830,6 @@ static BOOL doInit (void) init_row_map (); init_colors (); - if (currentmode->flags & DM_OVERLAY) - setoverlay (0); - #if defined (GFXFILTER) if (currentmode->flags & DM_SWSCALE) { S2X_init (currentmode->current_width, currentmode->current_height, @@ -2338,6 +1880,7 @@ oops: void WIN32GFX_PaletteChange(void) { +#if 0 HRESULT hr; if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) return; @@ -2349,10 +1892,12 @@ void WIN32GFX_PaletteChange(void) hr = DirectDraw_SetPalette (0); /* Set our real palette */ if (FAILED(hr)) write_log ("SetPalette(0) failed, %s\n", DXError (hr)); +#endif } int WIN32GFX_ClearPalette(void) { +#if 0 HRESULT hr; if (currentmode->current_depth > 8) return 1; @@ -2361,10 +1906,13 @@ int WIN32GFX_ClearPalette(void) if (FAILED(hr)) write_log ("SetPalette(1) failed, %s\n", DXError (hr)); return SUCCEEDED(hr); +#endif + return 0; } int WIN32GFX_SetPalette(void) { +#if 0 HRESULT hr; if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) return 1; if (currentmode->current_depth > 8) @@ -2373,11 +1921,11 @@ int WIN32GFX_SetPalette(void) if (FAILED(hr)) write_log ("SetPalette(0) failed, %s\n", DXError (hr)); return SUCCEEDED(hr); +#endif + return 0; } void WIN32GFX_WindowMove (void) { - if (currentmode->flags & DM_OVERLAY) - setoverlay(0); } void updatedisplayarea (void) @@ -2386,7 +1934,6 @@ void updatedisplayarea (void) return; if (picasso_on) return; - /* Update the display area */ #if defined (GFXFILTER) if (currentmode->flags & DM_OPENGL) { #if defined (OPENGL) @@ -2400,27 +1947,10 @@ void updatedisplayarea (void) #endif if (currentmode->flags & DM_DDRAW) { #if defined (GFXFILTER) - if (currentmode->flags & DM_SWSCALE) { + if (currentmode->flags & DM_SWSCALE) S2X_refresh (); - if(isfullscreen() <= 0) { - if(DirectDraw_GetLockableType() != overlay_surface) - DX_Blit(0, 0, 0, 0, WIN32GFX_GetWidth(), WIN32GFX_GetHeight(), BLIT_SRC); - } else { - DirectDraw_Blt(primary_surface, NULL, secondary_surface, NULL, DDBLT_WAIT, NULL); - } - } - else #endif - { - if (isfullscreen() <= 0) { - surface_type_e s; - s = DirectDraw_GetLockableType(); - if (s != overlay_surface && s != invalid_surface) - DX_Blit(0, 0, 0, 0, WIN32GFX_GetWidth(), WIN32GFX_GetHeight(), BLIT_SRC); - } else { - DirectDraw_Blt(primary_surface, NULL, secondary_surface, NULL, DDBLT_WAIT, NULL); - } - } + DirectDraw_Flip (0); } } @@ -2447,6 +1977,8 @@ void updatewinfsmode (struct uae_prefs *p) } if (!Displays[p->gfx_display].primary) displayGUID = &Displays[p->gfx_display].guid; + if (isfullscreen () == 0) + displayGUID = NULL; } void toggle_fullscreen (void) @@ -2469,7 +2001,7 @@ HDC gethdc (void) if (D3D_isenabled()) return D3D_getDC (0); #endif - if(FAILED(DirectDraw_GetDC(&hdc, DirectDraw_GetLockableType()))) + if(FAILED (DirectDraw_GetDC (&hdc))) hdc = 0; return hdc; } @@ -2488,5 +2020,5 @@ void releasehdc (HDC hdc) return; } #endif - DirectDraw_ReleaseDC(hdc, DirectDraw_GetLockableType()); + DirectDraw_ReleaseDC (hdc); } diff --git a/od-win32/win32gfx.h b/od-win32/win32gfx.h index 79764e61..9cf44929 100755 --- a/od-win32/win32gfx.h +++ b/od-win32/win32gfx.h @@ -6,29 +6,24 @@ extern void sortdisplays (void); extern void enumeratedisplays (int); -int WIN32GFX_IsPicassoScreen( void ); -int WIN32GFX_GetWidth( void ); -int WIN32GFX_GetHeight( void ); +int WIN32GFX_IsPicassoScreen (void); +int WIN32GFX_GetWidth (void); +int WIN32GFX_GetHeight(void); int WIN32GFX_GetDepth (int real); -void WIN32GFX_DisplayChangeRequested( void ); -void WIN32GFX_ToggleFullScreen( void ); -void WIN32GFX_DisablePicasso( void ); -void WIN32GFX_EnablePicasso( void ); -void WIN32GFX_PaletteChange( void ); -int WIN32GFX_ClearPalette( void ); -int WIN32GFX_SetPalette( void ); -void WIN32GFX_WindowMove ( void ); -void WIN32GFX_WindowSize ( void );; - -int DX_Blit( int srcx, int srcy, int dstx, int dsty, int width, int height, BLIT_OPCODE opcode ); - -#ifndef _WIN32_WCE -RGBFTYPE WIN32GFX_FigurePixelFormats( RGBFTYPE colortype ); -int WIN32GFX_AdjustScreenmode( uae_u32 *pwidth, uae_u32 *pheight, uae_u32 *ppixbits ); -#endif +void WIN32GFX_DisplayChangeRequested (void); +void WIN32GFX_ToggleFullScreen (void); +void WIN32GFX_DisablePicasso (void); +void WIN32GFX_EnablePicasso (void); +void WIN32GFX_PaletteChange (void); +int WIN32GFX_ClearPalette (void); +int WIN32GFX_SetPalette (void); +void WIN32GFX_WindowMove (void); +void WIN32GFX_WindowSize (void);; + +RGBFTYPE WIN32GFX_FigurePixelFormats (RGBFTYPE colortype); +int WIN32GFX_AdjustScreenmode (uae_u32 *pwidth, uae_u32 *pheight, uae_u32 *ppixbits); extern HWND hStatusWnd; -extern HINSTANCE hDDraw; extern uae_u32 default_freq; extern int normal_display_change_starting; extern int window_led_drives, window_led_drives_end; @@ -38,6 +33,10 @@ extern void releasehdc (HDC hdc); extern void close_windows (void); extern void updatewinfsmode (struct uae_prefs *p); extern int is3dmode (void); -extern void setoverlay(int); + +int DX_Fill (int dstx, int dsty, int width, int height, uae_u32 color); +int DX_Blit (int x, int y, int w, int h); +void centerdstrect (RECT *, RECT *); + #endif diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index 97811317..e76c2517 100755 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -119,6 +119,7 @@ extern char help_file[MAX_DPATH]; extern int mouseactive; char config_filename[MAX_DPATH] = ""; +static char stored_path[MAX_DPATH]; #define Error(x) MessageBox(NULL, (x), "WinUAE Error", MB_OK) @@ -254,27 +255,150 @@ static WCHAR *au (const char *s) MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, s, -1, d, len); return d; } +#define MAXFAVORITES 30 +static void writefavoritepaths (int num, char **values, char **paths) +{ + int i; + UAEREG *fkey; + + fkey = regcreatetree (NULL, "FavoritePaths"); + if (fkey == NULL) + return; + for (i = 0; i < num; i++) { + char str[MAX_DPATH]; + char key[100]; + if (!strcmp (values[i], paths[i])) + strcpy (str, values[i]); + else + sprintf (str, "%s \"%s\"", values[i], paths[i]); + sprintf (key, "PATH_ALL_%02d", i + 1); + regsetstr (fkey, key, str); + xfree (values[i]); + xfree (paths[i]); + } + while (i < MAXFAVORITES) { + char key[100]; + sprintf (key, "PATH_ALL_%02d", i + 1); + regdelete (fkey, key); + i++; + } + regclosetree (fkey); +} -static int popupmenu (HWND hwnd, const char **items) + +static int askinputcustom(HWND hDlg, char *custom, int maxlen); +static void addfavoritepath (HWND hDlg, const char *path, int num, char **values, char **paths) { - int i, item; - HMENU menu; - POINT pt; + char name[MAX_DPATH]; + if (num >= MAXFAVORITES) + return; + strcpy (name, path); + if (askinputcustom (hDlg, name, sizeof name)) { + values[num] = my_strdup (name); + paths[num] = my_strdup (path); + num++; + writefavoritepaths (num, values, paths); + } +} +static void removefavoritepath (int idx, int num, char **values, char **paths) +{ + int i; - menu = CreatePopupMenu(); + xfree (values[idx]); + xfree (paths[idx]); + values[idx] = paths[idx] = NULL; + for (i = idx; i < num - 1; i++) { + values[i] = values[i + 1]; + paths[i] = paths[i + 1]; + } + num--; + writefavoritepaths (num, values, paths); +} + +static void addeditmenu (HMENU menu, char **items) +{ + int i; + HMENU emenu = CreatePopupMenu(); + char newpath[MAX_DPATH]; + + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof mii; + + mii.fMask = MIIM_FTYPE; + mii.fType = MFT_SEPARATOR; + mii.fState = MFS_ENABLED; + InsertMenuItem (menu, -1, TRUE, &mii); + + if (!stored_path[0]) + GetModuleFileName(NULL, stored_path, MAX_DPATH); + while (stored_path[0]) { + DWORD v = GetFileAttributes (stored_path); + char *s; + if (v == INVALID_FILE_ATTRIBUTES) + break; + if (v & FILE_ATTRIBUTE_DIRECTORY) + break; + s = strrchr (stored_path, '\\'); + if (!s) + s = strrchr (stored_path, '/'); + if (!s) { + stored_path[0] = 0; + break; + } + s[0] = 0; + } + mii.fMask = MIIM_STRING | MIIM_ID; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + sprintf (newpath, "Add '%s'", stored_path); + mii.dwTypeData = newpath; + mii.cch = strlen (mii.dwTypeData); + mii.wID = 1000; + if (stored_path[0]) + InsertMenuItem (emenu, -1, TRUE, &mii); i = 0; while (items[i]) { - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof mii; mii.fMask = MIIM_STRING | MIIM_ID; mii.fType = MFT_STRING; mii.fState = MFS_ENABLED; - mii.wID = 1 + i; - mii.dwTypeData = items[i]; - mii.cch = strlen (items[i]); + mii.wID = 1001 + i; + sprintf (newpath, "Remove '%s'", items[i]); + mii.dwTypeData = newpath; + mii.cch = strlen (mii.dwTypeData); + InsertMenuItem (emenu, -1, TRUE, &mii); i++; - InsertMenuItem (menu, i, TRUE, &mii); } + + mii.fMask = MIIM_STRING | MIIM_SUBMENU; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + mii.dwTypeData = "Edit"; + mii.cch = strlen (mii.dwTypeData); + mii.hSubMenu = emenu; + InsertMenuItem (menu, -1, TRUE, &mii); +} + +static int popupmenu (HWND hwnd, char **items) +{ + int i, item; + HMENU menu; + POINT pt; + + menu = CreatePopupMenu(); + i = 0; + while (items[i]) { + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof mii; + mii.fMask = MIIM_STRING | MIIM_ID; + mii.fType = MFT_STRING; + mii.fState = MFS_ENABLED; + mii.wID = 1 + i; + mii.dwTypeData = items[i]; + mii.cch = strlen (mii.dwTypeData); + InsertMenuItem (menu, -1, TRUE, &mii); + i++; + } + addeditmenu (menu, items); GetCursorPos (&pt); item = TrackPopupMenu (menu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL); @@ -282,63 +406,79 @@ static int popupmenu (HWND hwnd, const char **items) DestroyMenu (menu); return item; } -#define MAXFAVORITES 30 static char *favoritepopup (HWND hwnd) { UAEREG *fkey; int idx, idx2; char *values[MAXFAVORITES + 1]; char *paths[MAXFAVORITES + 1]; - int ret, i, num; + int ret, i, j, num; - fkey = regcreatetree (NULL, "FavoritePaths"); - if (fkey == NULL) - return NULL; - idx = 0; - num = 0; for (;;) { - char *p; - DWORD size, size2; - char tmp[1000], tmp2[1000]; - size = sizeof (tmp); - size2 = sizeof (tmp2); - if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) - break; - p = strrchr (tmp, '_'); - if (p) { - idx2 = atol (p + 1); - if (idx2 > 0 && idx2 < MAXFAVORITES) { - char *p2 = strchr (tmp2, '"'); - char *str, *fname; - idx2--; - if (p2) { - fname = my_strdup (p2 + 1); - p2[0] = 0; - p2 = strchr (fname, '"'); - if (p2) - *p2 = 0; - str = my_strdup (tmp2); - } else { + fkey = regcreatetree (NULL, "FavoritePaths"); + if (fkey == NULL) + return NULL; + idx = 0; + num = 0; + for (;;) { + char *p; + DWORD size, size2; + char tmp[1000], tmp2[1000]; + size = sizeof (tmp); + size2 = sizeof (tmp2); + if (!regenumstr (fkey, idx, tmp, &size, tmp2, &size2)) + break; + p = strrchr (tmp, '_'); + if (p) { + idx2 = atol (p + 1); + if (idx2 > 0 && idx2 < MAXFAVORITES) { + char *p2 = strchr (tmp2, '"'); + char *str, *fname; + idx2--; + if (p2) { + fname = my_strdup (p2 + 1); + p2[0] = 0; + p2 = strchr (fname, '"'); + if (p2) + *p2 = 0; + str = my_strdup (tmp2); + } else { + str = my_strdup (tmp2); + fname = my_strdup (tmp2); + } str = my_strdup (tmp2); - fname = my_strdup (tmp2); + paths[idx2] = fname; + values[idx2] = str; } - str = my_strdup (tmp2); - paths[idx2] = fname; - values[idx2] = str; } + idx++; + } + regclosetree (fkey); + for (i = 0; i < idx; i++) { + for (j = i + 1; j < idx; j++) { + if (strcmp (values[i], values[j]) > 0) { + char *tmp = values[i]; + values[i] = values[j]; + values[j] = tmp; + tmp = paths[i]; + paths[i] = paths[j]; + paths[j] = tmp; + } + } + } + values[idx] = NULL; + ret = popupmenu (hwnd, values); + if (ret == 0) + break; + if (ret <= idx) + break; + if (ret == 1000) { + if (stored_path[0]) + addfavoritepath (hwnd, stored_path, idx, values, paths); + } else if (ret > 1000) { + removefavoritepath (ret - 1001, idx, values, paths); } - idx++; } - regclosetree (fkey); - if (idx == 0) { - values[idx++] = my_strdup ("d:\\amiga\\stuff\\demos"); - values[idx++] = my_strdup ("d:\\amiga\\stuff\\games"); - values[idx++] = my_strdup ("c:\\windows"); - for (i = 0; i < idx; i++) - paths[i] = my_strdup (values[i]); - } - values[idx] = NULL; - ret = popupmenu (hwnd, values); for (i = 0; i < idx; i++) { xfree (values[i]); if (i + 1 != ret) @@ -1366,6 +1506,7 @@ int DiskSelection_2 (HWND hDlg, WPARAM wParam, int flag, struct uae_prefs *prefs write_log ("GetOpenFileName() failed, err=%d.\n", GetLastError()); } memcpy (full_path2, full_path, sizeof (full_path)); + memcpy (stored_path, full_path, sizeof (stored_path)); next = 0; nextp = full_path2 + openFileName.nFileOffset; if (path_out) { @@ -1530,7 +1671,7 @@ static int loopmulti (char *s, char *out) return 1; } -static BOOL CreateHardFile (HWND hDlg, UINT hfsizem, char *dostype) +static BOOL CreateHardFile (HWND hDlg, UINT hfsizem, char *dostype, char *newpath) { HANDLE hf; int i = 0; @@ -1543,7 +1684,8 @@ static BOOL CreateHardFile (HWND hDlg, UINT hfsizem, char *dostype) uae_u8 b; hfsize = (uae_u64)hfsizem * 1024 * 1024; - DiskSelection (hDlg, IDC_PATH_NAME, 3, &workprefs, 0); + if (!DiskSelection (hDlg, IDC_PATH_NAME, 3, &workprefs, newpath)) + return FALSE; GetDlgItemText (hDlg, IDC_PATH_NAME, init_path, MAX_DPATH); if (*init_path && hfsize) { SetCursor (LoadCursor(NULL, IDC_WAIT)); @@ -1581,6 +1723,13 @@ static BOOL CreateHardFile (HWND hDlg, UINT hfsizem, char *dostype) } SetCursor (LoadCursor (NULL, IDC_ARROW)); } + if (!result) { + char szMessage[MAX_DPATH]; + char szTitle[MAX_DPATH]; + WIN32GUI_LoadUIString (IDS_FAILEDHARDFILECREATION, szMessage, MAX_DPATH); + WIN32GUI_LoadUIString (IDS_CREATIONERROR, szTitle, MAX_DPATH); + MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + } return result; } @@ -1833,7 +1982,7 @@ static struct ConfigStruct *CreateConfigStore (struct ConfigStruct *oldconfig) return 0; } -static char *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *config) +static char *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *config, char *newpath) { char name[MAX_DPATH], desc[MAX_DPATH]; char path[MAX_DPATH]; @@ -1861,11 +2010,11 @@ static char *HandleConfiguration (HWND hDlg, int flag, struct ConfigStruct *conf switch (flag) { case CONFIG_SAVE_FULL: - DiskSelection(hDlg, IDC_SAVE, 5, &workprefs, 0); + DiskSelection(hDlg, IDC_SAVE, 5, &workprefs, newpath); break; case CONFIG_LOAD_FULL: - DiskSelection(hDlg, IDC_LOAD, 4, &workprefs, 0); + DiskSelection(hDlg, IDC_LOAD, 4, &workprefs, newpath); EnableWindow(GetDlgItem (hDlg, IDC_VIEWINFO), workprefs.info[0]); break; @@ -2619,9 +2768,99 @@ static struct ConfigStruct *initloadsave (HWND hDlg, struct ConfigStruct *config return config; } +static void loadsavecommands (HWND hDlg, WPARAM wParam, struct ConfigStruct *config, char **pcfgfile, char *newpath) +{ + switch (LOWORD (wParam)) + { + case IDC_SAVE: + HandleConfiguration (hDlg, CONFIG_SAVE_FULL, config, newpath); + config = CreateConfigStore (config); + config = fixloadconfig (hDlg, config); + ConfigToRegistry (config, configtypepanel); + InitializeConfigTreeView (hDlg); + InitializeConfig (hDlg, config); + break; + case IDC_QUICKSAVE: + HandleConfiguration (hDlg, CONFIG_SAVE, config, NULL); + config = CreateConfigStore (config); + config = fixloadconfig (hDlg, config); + ConfigToRegistry (config, configtypepanel); + InitializeConfigTreeView (hDlg); + InitializeConfig (hDlg, config); + break; + case IDC_QUICKLOAD: + *pcfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config, NULL); + ConfigToRegistry (config, configtypepanel); + InitializeConfig (hDlg, config); + if (full_property_sheet) { + inputdevice_updateconfig (&workprefs); + } else { + uae_restart (-1, *pcfgfile); + exit_gui(1); + } + break; + case IDC_LOAD: + *pcfgfile = HandleConfiguration (hDlg, CONFIG_LOAD_FULL, config, newpath); + ConfigToRegistry (config, configtypepanel); + InitializeConfig (hDlg, config); + if (full_property_sheet) { + inputdevice_updateconfig (&workprefs); + } else { + uae_restart (-1, *pcfgfile); + exit_gui(1); + } + break; + case IDC_DELETE: + HandleConfiguration (hDlg, CONFIG_DELETE, config, NULL); + config = CreateConfigStore (config); + config = fixloadconfig (hDlg, config); + InitializeConfigTreeView (hDlg); + break; + case IDC_VIEWINFO: + if (workprefs.info[0]) { + char name_buf[MAX_DPATH]; + if (strstr (workprefs.info, "Configurations\\")) + sprintf (name_buf, "%s\\%s", start_path_data, workprefs.info); + else + strcpy (name_buf, workprefs.info); + ShellExecute (NULL, NULL, name_buf, NULL, NULL, SW_SHOWNORMAL); + } + break; + case IDC_SETINFO: + if (CustomDialogBox(IDD_SETINFO, hDlg, InfoSettingsProc)) + EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] ); + break; + case IDC_CONFIGAUTO: + if (configtypepanel > 0) { + int ct = IsDlgButtonChecked (hDlg, IDC_CONFIGAUTO) == BST_CHECKED ? 1 : 0; + ConfigToRegistry2 (ct, configtypepanel, -1); + } + break; + case IDC_CONFIGNOLINK: + if (configtypepanel == 0) { + int ct = IsDlgButtonChecked (hDlg, IDC_CONFIGNOLINK) == BST_CHECKED ? 1 : 0; + ConfigToRegistry2 (-1, -1, ct); + } + break; + case IDC_CONFIGLINK: + if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { + LRESULT val; + char tmp[MAX_DPATH]; + tmp[0] = 0; + val = SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETCURSEL, 0, 0L); + if (val == CB_ERR) + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, WM_GETTEXT, (WPARAM)sizeof(tmp), (LPARAM)tmp); + else + SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); + strcpy (workprefs.config_host_path, tmp); + } + break; + } +} + static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - char *cfgfile; + char *cfgfile = NULL; static int recursive; static struct ConfigStruct *config; @@ -2642,95 +2881,23 @@ static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA case WM_USER: break; - case WM_COMMAND: + case WM_CONTEXTMENU: { - recursive++; - switch (LOWORD (wParam)) - { - case IDC_SAVE: - HandleConfiguration (hDlg, CONFIG_SAVE_FULL, config); - config = CreateConfigStore (config); - config = fixloadconfig (hDlg, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfigTreeView (hDlg); - InitializeConfig (hDlg, config); - break; - case IDC_QUICKSAVE: - HandleConfiguration (hDlg, CONFIG_SAVE, config); - config = CreateConfigStore (config); - config = fixloadconfig (hDlg, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfigTreeView (hDlg); - InitializeConfig (hDlg, config); - break; - case IDC_QUICKLOAD: - cfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfig (hDlg, config); - if (full_property_sheet) { - inputdevice_updateconfig (&workprefs); - } else { - uae_restart (-1, cfgfile); - exit_gui(1); - } - break; - case IDC_LOAD: - cfgfile = HandleConfiguration (hDlg, CONFIG_LOAD_FULL, config); - ConfigToRegistry (config, configtypepanel); - InitializeConfig (hDlg, config); - if (full_property_sheet) { - inputdevice_updateconfig (&workprefs); - } else { - uae_restart (-1, cfgfile); - exit_gui(1); - } - break; - case IDC_DELETE: - HandleConfiguration (hDlg, CONFIG_DELETE, config); - config = CreateConfigStore (config); - config = fixloadconfig (hDlg, config); - InitializeConfigTreeView (hDlg); - break; - case IDC_VIEWINFO: - if (workprefs.info[0]) { - char name_buf[MAX_DPATH]; - if (strstr (workprefs.info, "Configurations\\")) - sprintf (name_buf, "%s\\%s", start_path_data, workprefs.info); - else - strcpy (name_buf, workprefs.info); - ShellExecute (NULL, NULL, name_buf, NULL, NULL, SW_SHOWNORMAL); - } - break; - case IDC_SETINFO: - if (CustomDialogBox(IDD_SETINFO, hDlg, InfoSettingsProc)) - EnableWindow( GetDlgItem( hDlg, IDC_VIEWINFO ), workprefs.info[0] ); - break; - case IDC_CONFIGAUTO: - if (configtypepanel > 0) { - int ct = IsDlgButtonChecked (hDlg, IDC_CONFIGAUTO) == BST_CHECKED ? 1 : 0; - ConfigToRegistry2 (ct, configtypepanel, -1); - } - break; - case IDC_CONFIGNOLINK: - if (configtypepanel == 0) { - int ct = IsDlgButtonChecked (hDlg, IDC_CONFIGNOLINK) == BST_CHECKED ? 1 : 0; - ConfigToRegistry2 (-1, -1, ct); - } - break; - case IDC_CONFIGLINK: - if (HIWORD (wParam) == CBN_SELCHANGE || HIWORD (wParam) == CBN_KILLFOCUS) { - LRESULT val; - char tmp[MAX_DPATH]; - tmp[0] = 0; - val = SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETCURSEL, 0, 0L); - if (val == CB_ERR) - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, WM_GETTEXT, (WPARAM)sizeof(tmp), (LPARAM)tmp); - else - SendDlgItemMessage (hDlg, IDC_CONFIGLINK, CB_GETLBTEXT, (WPARAM)val, (LPARAM)tmp); - strcpy (workprefs.config_host_path, tmp); + int id = GetDlgCtrlID((HWND)wParam); + if (id == IDC_SAVE || id == IDC_LOAD) { + char *s = favoritepopup (hDlg); + if (s) { + loadsavecommands (hDlg, id, config, &cfgfile, s); + xfree (s); } - break; } + break; + } + + case WM_COMMAND: + { + recursive++; + loadsavecommands (hDlg, wParam, config, &cfgfile, NULL); recursive++; break; } @@ -2752,7 +2919,7 @@ static INT_PTR CALLBACK LoadSaveDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA if (TreeView_GetItem (GetDlgItem(hDlg, IDC_CONFIGTREE), &pitem)) { struct ConfigStruct *config = (struct ConfigStruct*)pitem.lParam; if (config && !config->Directory) { - cfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config); + cfgfile = HandleConfiguration (hDlg, CONFIG_LOAD, config, NULL); ConfigToRegistry (config, configtypepanel); if (!full_property_sheet) uae_restart (0, cfgfile); @@ -4660,7 +4827,6 @@ static void enable_for_memorydlg (HWND hDlg) ew (hDlg, IDC_MBMEM1, z3); ew (hDlg, IDC_MBRAM2, z3); ew (hDlg, IDC_MBMEM2, z3); - ew (hDlg, IDC_P96MODE, full_property_sheet); } static void values_to_memorydlg (HWND hDlg) @@ -4766,12 +4932,6 @@ static void values_to_memorydlg (HWND hDlg) } SendDlgItemMessage (hDlg, IDC_MBMEM2, TBM_SETPOS, TRUE, mem_size); SetDlgItemText (hDlg, IDC_MBRAM2, memsize_names[msi_gfx[mem_size]]); - - SendDlgItemMessage(hDlg, IDC_P96MODE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage (hDlg, IDC_P96MODE, CB_ADDSTRING, 0, (LPARAM)"P96-OLD"); - SendDlgItemMessage (hDlg, IDC_P96MODE, CB_ADDSTRING, 0, (LPARAM)"P96-NEW"); - SendDlgItemMessage (hDlg, IDC_P96MODE, CB_SETCURSEL, p96mode, 0); - } static void fix_values_memorydlg (void) @@ -4823,10 +4983,6 @@ static INT_PTR CALLBACK MemoryDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARA if (recursive > 0) break; recursive++; - if (LOWORD (wParam) == IDC_P96MODE && full_property_sheet) { - p96mode = SendDlgItemMessage (hDlg, IDC_P96MODE, CB_GETCURSEL, 0, 0); - regsetint (NULL, "p96mode", p96mode); - } values_to_memorydlg (hDlg); recursive--; break; @@ -5060,7 +5216,7 @@ static void enable_for_miscdlg (HWND hDlg) ew (hDlg, IDC_NOSPEED, TRUE); ew (hDlg, IDC_NOSPEEDPAUSE, TRUE); ew (hDlg, IDC_NOSOUND, TRUE); - ew (hDlg, IDC_NOOVERLAY, TRUE); + ew (hDlg, IDC_RTGMATCHDEPTH, TRUE); ew (hDlg, IDC_DOSAVESTATE, TRUE); ew (hDlg, IDC_SCSIMODE, FALSE); ew (hDlg, IDC_SCSIDEVICE, FALSE); @@ -5208,7 +5364,7 @@ static void values_to_miscdlg (HWND hDlg) CheckDlgButton (hDlg, IDC_JULIAN, workprefs.win32_middle_mouse); CheckDlgButton (hDlg, IDC_CREATELOGFILE, workprefs.win32_logfile); CheckDlgButton (hDlg, IDC_CTRLF11, workprefs.win32_ctrl_F11_is_quit); - CheckDlgButton (hDlg, IDC_NOOVERLAY, workprefs.win32_no_overlay); + CheckDlgButton (hDlg, IDC_RTGMATCHDEPTH, workprefs.win32_rtgmatchdepth); CheckDlgButton (hDlg, IDC_SHOWLEDS, workprefs.leds_on_screen); CheckDlgButton (hDlg, IDC_SCSIDEVICE, workprefs.scsi == 1); CheckDlgButton (hDlg, IDC_SANA2, workprefs.sana2); @@ -5282,6 +5438,28 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) recursive--; return TRUE; + case WM_CONTEXTMENU: + if (GetDlgCtrlID((HWND)wParam) == IDC_DOSAVESTATE) { + char *s = favoritepopup (hDlg); + if (s) { + char path[MAX_DPATH]; + strcpy (path, s); + xfree (s); + if (DiskSelection(hDlg, wParam, 9, &workprefs, path)) + save_state (savestate_fname, "Description!"); + } + } else if (GetDlgCtrlID((HWND)wParam) == IDC_DOLOADSTATE) { + char *s = favoritepopup (hDlg); + if (s) { + char path[MAX_DPATH]; + strcpy (path, s); + xfree (s); + if (DiskSelection(hDlg, wParam, 10, &workprefs, path)) + savestate_state = STATE_DORESTORE; + } + } + break; + case WM_COMMAND: if (currentpage == MISC1_ID) { @@ -5347,8 +5525,8 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_JULIAN: workprefs.win32_middle_mouse = IsDlgButtonChecked(hDlg, IDC_JULIAN); break; - case IDC_NOOVERLAY: - workprefs.win32_no_overlay = IsDlgButtonChecked(hDlg, IDC_NOOVERLAY); + case IDC_RTGMATCHDEPTH: + workprefs.win32_rtgmatchdepth = IsDlgButtonChecked(hDlg, IDC_RTGMATCHDEPTH); break; case IDC_SHOWLEDS: workprefs.leds_on_screen = IsDlgButtonChecked(hDlg, IDC_SHOWLEDS); @@ -6198,13 +6376,52 @@ static struct hfdlg_vals empty_hfdlg = { "", "", "", "", 32, 2, 1, 0, 512, 1, 0, static struct hfdlg_vals current_hfdlg; static int archivehd; -static INT_PTR CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static void volumeselectfile (HWND hDlg) +{ + char directory_path[MAX_DPATH]; + strcpy (directory_path, current_fsvdlg.rootdir); + if (DiskSelection(hDlg, 0, 14, &workprefs, directory_path)) { + char *s = filesys_createvolname (NULL, directory_path, "Harddrive"); + SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path); + SetDlgItemText (hDlg, IDC_VOLUME_NAME, s); + xfree (s); + CheckDlgButton (hDlg, IDC_FS_RW, FALSE); + ew (hDlg, IDC_FS_RW, FALSE); + archivehd = 1; + } +} +static void volumeselectdir (HWND hDlg, int newdir) { - static int recursive = 0; BROWSEINFO browse_info; - char directory_path[MAX_DPATH] = ""; LPITEMIDLIST browse; char szTitle[MAX_DPATH]; + char directory_path[MAX_DPATH]; + + strcpy (directory_path, current_fsvdlg.rootdir); + if (!newdir) { + WIN32GUI_LoadUIString(IDS_SELECTFILESYSROOT, szTitle, MAX_DPATH); + browse_info.hwndOwner = hDlg; + browse_info.pidlRoot = NULL; + browse_info.pszDisplayName = directory_path; + browse_info.lpszTitle = ""; + browse_info.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS; + browse_info.lpfn = NULL; + browse_info.iImage = 0; + if ((browse = SHBrowseForFolder (&browse_info)) != NULL) { + SHGetPathFromIDList (browse, directory_path); + newdir = 1; + } + } + if (newdir) { + SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path); + ew (hDlg, IDC_FS_RW, TRUE); + archivehd = 0; + } +} + +static INT_PTR CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static int recursive = 0; switch (msg) { case WM_INITDIALOG: @@ -6230,6 +6447,24 @@ static INT_PTR CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, } return TRUE; + case WM_CONTEXTMENU: + if (GetDlgCtrlID((HWND)wParam) == IDC_FS_SELECT_FILE) { + char *s = favoritepopup (hDlg); + if (s) { + strcpy (current_fsvdlg.rootdir, s); + xfree (s); + volumeselectfile (hDlg); + } + } else if (GetDlgCtrlID((HWND)wParam) == IDC_FS_SELECT_DIR) { + char *s = favoritepopup (hDlg); + if (s) { + strcpy (current_fsvdlg.rootdir, s); + xfree (s); + volumeselectdir (hDlg, 1); + } + } + break; + case WM_COMMAND: if (recursive) break; @@ -6245,33 +6480,10 @@ static INT_PTR CALLBACK VolumeSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, archivehd = -1; break; case IDC_FS_SELECT_FILE: - strcpy (directory_path, current_fsvdlg.rootdir); - if (DiskSelection(hDlg, 0, 14, &workprefs, directory_path)) { - char *s = filesys_createvolname (NULL, directory_path, "Harddrive"); - SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path); - SetDlgItemText (hDlg, IDC_VOLUME_NAME, s); - xfree (s); - CheckDlgButton (hDlg, IDC_FS_RW, FALSE); - ew (hDlg, IDC_FS_RW, FALSE); - archivehd = 1; - } + volumeselectfile (hDlg); break; case IDC_FS_SELECT_DIR: - strcpy (directory_path, current_fsvdlg.rootdir); - WIN32GUI_LoadUIString(IDS_SELECTFILESYSROOT, szTitle, MAX_DPATH); - browse_info.hwndOwner = hDlg; - browse_info.pidlRoot = NULL; - browse_info.pszDisplayName = directory_path; - browse_info.lpszTitle = ""; - browse_info.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS; - browse_info.lpfn = NULL; - browse_info.iImage = 0; - if ((browse = SHBrowseForFolder (&browse_info)) != NULL) { - SHGetPathFromIDList (browse, directory_path); - SetDlgItemText (hDlg, IDC_PATH_NAME, directory_path); - ew (hDlg, IDC_FS_RW, TRUE); - archivehd = 0; - } + volumeselectdir (hDlg, 0); break; case IDOK: EndDialog (hDlg, 1); @@ -6440,6 +6652,26 @@ static void updatehdfinfo (HWND hDlg, int force) SetDlgItemText (hDlg, IDC_HDFINFO, tmp); } +static void hardfileselecthdf (HWND hDlg, char *newpath) +{ + DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs, newpath); + GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename, sizeof current_hfdlg.filename); + inithardfile(hDlg); + hardfile_testrdb (hDlg, ¤t_hfdlg); + updatehdfinfo (hDlg, 1); +} + +static void hardfilecreatehdf (HWND hDlg, char *newpath) +{ + LRESULT res; + UINT setting = CalculateHardfileSize (hDlg); + char dostype[16]; + GetDlgItemText (hDlg, IDC_HF_DOSTYPE, dostype, sizeof (dostype)); + res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); + if (res == 0) + dostype[0] = 0; + CreateHardFile(hDlg, setting, dostype, newpath); +} static INT_PTR CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -6458,6 +6690,34 @@ static INT_PTR CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam recursive--; return TRUE; + case WM_CONTEXTMENU: + if (GetDlgCtrlID((HWND)wParam) == IDC_SELECTOR) { + char *s = favoritepopup (hDlg); + if (s) { + char path[MAX_DPATH]; + strcpy (path, s); + xfree (s); + hardfileselecthdf (hDlg, path); + } + } else if (GetDlgCtrlID((HWND)wParam) == IDC_FILESYS_SELECTOR) { + char *s = favoritepopup (hDlg); + if (s) { + char path[MAX_DPATH]; + strcpy (path, s); + xfree (s); + DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, path); + } + } else if (GetDlgCtrlID((HWND)wParam) == IDC_HF_CREATE) { + char *s = favoritepopup (hDlg); + if (s) { + char path[MAX_DPATH]; + strcpy (path, s); + xfree (s); + hardfilecreatehdf (hDlg, path); + } + } + break; + case WM_COMMAND: if (recursive) break; @@ -6473,45 +6733,21 @@ static INT_PTR CALLBACK HardfileSettingsProc (HWND hDlg, UINT msg, WPARAM wParam ew (hDlg, IDC_HF_DOSTYPE, res >= 2); break; case IDC_HF_CREATE: - { - UINT setting = CalculateHardfileSize (hDlg); - char dostype[16]; - GetDlgItemText (hDlg, IDC_HF_DOSTYPE, dostype, sizeof (dostype)); - res = SendDlgItemMessage (hDlg, IDC_HF_TYPE, CB_GETCURSEL, 0, 0); - if (res == 0) - dostype[0] = 0; - if (!CreateHardFile(hDlg, setting, dostype)) { - char szMessage[MAX_DPATH]; - char szTitle[MAX_DPATH]; - WIN32GUI_LoadUIString (IDS_FAILEDHARDFILECREATION, szMessage, MAX_DPATH); - WIN32GUI_LoadUIString (IDS_CREATIONERROR, szTitle, MAX_DPATH); - MessageBox(hDlg, szMessage, szTitle, - MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); - } - } + hardfilecreatehdf (hDlg, NULL); break; case IDC_SELECTOR: - { - DiskSelection (hDlg, IDC_PATH_NAME, 2, &workprefs, 0); - GetDlgItemText (hDlg, IDC_PATH_NAME, current_hfdlg.filename, sizeof current_hfdlg.filename); - inithardfile(hDlg); - hardfile_testrdb (hDlg, ¤t_hfdlg); - updatehdfinfo (hDlg, 1); - break; - } + hardfileselecthdf (hDlg, NULL); + break; case IDC_FILESYS_SELECTOR: DiskSelection (hDlg, IDC_PATH_FILESYS, 12, &workprefs, 0); break; case IDOK: - if(strlen(current_hfdlg.filename) == 0 ) - { + if(strlen(current_hfdlg.filename) == 0) { char szMessage[MAX_DPATH]; char szTitle[MAX_DPATH]; WIN32GUI_LoadUIString(IDS_MUSTSELECTFILE, szMessage, MAX_DPATH); WIN32GUI_LoadUIString(IDS_SETTINGSERROR, szTitle, MAX_DPATH); - - MessageBox( hDlg, szMessage, szTitle, - MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); + MessageBox( hDlg, szMessage, szTitle, MB_OK | MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND); break; } EndDialog (hDlg, 1); @@ -7535,11 +7771,14 @@ static void swapperhili (HWND hDlg, int entry) SetDlgItemText (hDlg, IDC_DISKTEXT, workprefs.dfxlist[entry]); } -static void addswapperfile (HWND hDlg, int entry) +static void addswapperfile (HWND hDlg, int entry, char *newpath) { char path[MAX_DPATH]; int lastentry = entry; + path[0] = 0; + if (newpath) + strcpy (path, newpath); if (MultiDiskSelection (hDlg, -1, 0, &changed_prefs, path)) { char dpath[MAX_DPATH]; loopmulti (path, NULL); @@ -7596,6 +7835,15 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR if (drag_move (hDlg, lParam)) return TRUE; break; + case WM_CONTEXTMENU: + if (GetDlgCtrlID((HWND)wParam) == IDC_DISKLISTINSERT && entry >= 0) { + char *s = favoritepopup (hDlg); + if (s) { + addswapperfile (hDlg, entry, s); + xfree (s); + } + } + break; case WM_COMMAND: { switch (LOWORD(wParam)) @@ -7673,7 +7921,7 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR break; case 10209: { - addswapperfile (hDlg, entry); + addswapperfile (hDlg, entry, NULL); } break; @@ -7685,7 +7933,7 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR InitializeListView (hDlg); swapperhili (hDlg, entry); } else { - addswapperfile (hDlg, entry); + addswapperfile (hDlg, entry, NULL); } } break; @@ -7760,7 +8008,7 @@ static INT_PTR CALLBACK SwapperDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPAR } else if (col == 1) { if (dblclick) { if (!button) { - addswapperfile (hDlg, entry); + addswapperfile (hDlg, entry, NULL); } else { workprefs.dfxlist[entry][0] = 0; InitializeListView (hDlg); diff --git a/od-win32/winuaechangelog.txt b/od-win32/winuaechangelog.txt index 6c90a4d9..04ec2b4d 100755 --- a/od-win32/winuaechangelog.txt +++ b/od-win32/winuaechangelog.txt @@ -1,9 +1,39 @@ +Beta 5: + +NOTE: filters are currently not supported, they may or may not work +NOTE: filter support rewrite coming soon.. +NOTE: vsync not supported. expect flashes or other issues.. + +- "favorite path" editing added. Path added is always last opened + path from any file select dialog. (later..) +- "favorite path" right button context menus added to most path + selection buttons +- picasso96.c clean up, removed old p96mode and other unused code +- new p96mode works without JIT +- CHK.L is 68020+, not 68000+ (only CHK.W is 68000+) +- uaescsi.device missing CMD_GETGEOMETRY added (not sure if "geometry" + data is correct but at least device type and removable flag is set) +- RGB overlay option is gone, not very useful anymore and newer + display drivers seem to emulate this in software.. +- big directdraw support rewrite +- fullscreen to different fullscreen mode switching should be quick + now (no more switching back to desktop and then back to fullscreen) +- 16 bit modes should work correctly again +- Windows-side 8 bit modes (temporarily) disabled. 8-bit RTG modes + still work and are automatically converted to 16/32-bit +- "Match RTG color depth" option added to misc-panel. If checked + fullscreen RTG mode uses Amiga-side color depth (as previously) + Not checked = always use Display panel depth setting. + Windowed mode always uses desktop color depth + + Beta 4: NOTE: Fullscreen RTG modes are not fully working yet. Do not use. NOTE: Before benchmarking, make sure Display panel display depth matches Picasso96 display depth. +NOTE: P96 OLD-mode not supported. Only use NEW-mode. - "Full-window" mode does not reopen window when switching modes - 16 and 8-bit RTG mode optimized blitter operations diff --git a/scsiemul.c b/scsiemul.c index 0e948bd5..c4506874 100755 --- a/scsiemul.c +++ b/scsiemul.c @@ -534,6 +534,21 @@ static int dev_do_io (struct devstruct *dev, uaecptr request) case CMD_GETNUMTRACKS: io_actual = dev->di.cylinders; break; + case CMD_GETGEOMETRY: + { + struct device_info di2, *di; + di = devinfo (pdev->mode, dev->unitnum, &di2); + put_long (io_data + 0, di->bytespersector); + put_long (io_data + 4, di->sectorspertrack * di->trackspercylinder * di->cylinders); + put_long (io_data + 8, di->cylinders); + put_long (io_data + 12, di->sectorspertrack * di->trackspercylinder); + put_long (io_data + 16, di->trackspercylinder); + put_long (io_data + 20, di->sectorspertrack); + put_long (io_data + 24, 0); /* bufmemtype */ + put_byte (io_data + 28, di->type); + put_byte (io_data + 29, di->removable ? 1 : 0); /* flags */ + } + break; case CMD_ADDCHANGEINT: io_error = add_async_request (dev, request, ASYNC_REQUEST_CHANGEINT, io_data); if (!io_error) diff --git a/table68k b/table68k index 7b595b13..ab4c84ef 100755 --- a/table68k +++ b/table68k @@ -143,7 +143,7 @@ 0100 1110 0111 1010:12:?????:?????:10: MOVEC2 #1 0100 1110 0111 1011:12:?????:?????:10: MOVE2C #1 0100 1110 10ss sSSS:00://///://///:80: JSR.L s[!Dreg,Areg,Aipi,Apdi,Immd] -0100 rrr1 00ss sSSS:00:?????:?????:11: CHK.L s[!Areg],Dr +0100 rrr1 00ss sSSS:20:?????:?????:11: CHK.L s[!Areg],Dr 0100 rrr1 10ss sSSS:00:?????:?????:11: CHK.W s[!Areg],Dr 0100 1110 11ss sSSS:00://///://///:80: JMP.L s[!Dreg,Areg,Aipi,Apdi,Immd] 0100 rrr1 11ss sSSS:00:-----:-----:02: LEA.L s[!Dreg,Areg,Aipi,Apdi,Immd],Ar -- 2.47.3